参见我的 MWE:
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage[per-mode = fraction]{siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization[
scientific axes = clean,
all axes = grid,
x axis = {
logarithmic,
ticks = {
step = 1,
minor steps between steps = 9
},
label = $\omega\,\si{\radian\per\s}$
},
y axis = {
ticks = {step = 45},
label = $\frac{\varphi(\omega)}{\si{\degree}}$
},
visualize as line/.list = {
P,
PD 1,
PD 2,
I,
PT_1 1,
PT_1 2,
phase
},
style sheet = vary thickness and dashing,
P = {label in legend = {text = P}},
PD 1 = {label in legend = {text = PD (1)}},
PD 2 = {label in legend = {text = PD (2)}},
I = {label in legend = {text = I}},
PT_1 1 = {label in legend = {text = PT$_{1,1}$}},
PT_1 2 = {label in legend = {text = PT$_{1,2}$}},
phase = {label in legend = {text = $\arg\{G_S(j\omega)\}$}}
]
data[set = P] {
x, y
.0001, 0
10000, 0
}
data[set = PD 1] {
x, y
.0001, 0
.001, 0
.1, 90
10000, 90
}
data[set = PD 2] {
x, y
.0001, 0
10, 0
1000, 90
10000, 90
}
data[set = I] {
x, y
.0001, -90
10000, -90
}
data[set = PT_1 1] {
x, y
.0001, 0
.01, 0
1, -90
10000, -90
}
data[set = PT_1 2] {
x, y
.0001, 0
1, 0
100, -90
10000, -90
}
data[set = phase] {
x, y
.0001, -90
.001, -90
.01, -45
.1, -45
10, -135
100, -135
1000, -90
10000, -90
};
\end{tikzpicture}
\end{document}
结果
如您所见,频率轴的刻度标签重叠。如何实现以下行为?
提前感谢您的帮助和努力!
答案1
您可以使用 键更改排版刻度标签的功能tick typesetter
,并使用 键使其变小node style
。
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage[per-mode = fraction]{siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\def\printonlypower#1{%
\pgfmathparse{int(round(log10{#1}))}%
\(10^{\pgfmathresult}\)%
}
\def\printonlyexponent#1{%
\pgfmathparse{int(round(log10{#1}))}%
\(\pgfmathresult\)%
}
\begin{document}
\begin{tikzpicture}
\datavisualization [
scientific axes = clean,
all axes = grid,
x axis = {
logarithmic,
ticks = {
step = 1,
minor steps between steps = 9,
node style={font=\tiny},
tick typesetter/.code={\printonlypower{##1}},
},
label = $\omega\,\si{\radian\per\s}$,
},
y axis = {
ticks = {step = 45},
label = $\frac{\varphi(\omega)}{\si{\degree}}$
},
visualize as line/.list = {
P,
PD 1,
PD 2,
I,
PT_1 1,
PT_1 2,
phase
},
style sheet = vary thickness and dashing,
P = {label in legend = {text = P}},
PD 1 = {label in legend = {text = PD (1)}},
PD 2 = {label in legend = {text = PD (2)}},
I = {label in legend = {text = I}},
PT_1 1 = {label in legend = {text = PT$_{1,1}$}},
PT_1 2 = {label in legend = {text = PT$_{1,2}$}},
phase = {label in legend = {text = $\arg\{G_S(j\omega)\}$}},
]
data[set = P] {
x, y
.0001, 0
10000, 0
}
data[set = PD 1] {
x, y
.0001, 0
.001, 0
.1, 90
10000, 90
}
data[set = PD 2] {
x, y
.0001, 0
10, 0
1000, 90
10000, 90
}
data[set = I] {
x, y
.0001, -90
10000, -90
}
data[set = PT_1 1] {
x, y
.0001, 0
.01, 0
1, -90
10000, -90
}
data[set = PT_1 2] {
x, y
.0001, 0
1, 0
100, -90
10000, -90
}
data[set = phase] {
x, y
.0001, -90
.001, -90
.01, -45
.1, -45
10, -135
100, -135
1000, -90
10000, -90
};
\end{tikzpicture}
\end{document}
但是,我强烈建议你不要把刻度标签做得那么小;这样太难读了。相反,把图做得大一点,这样刻度标签就合适了。这样scale=1.5
你就会得到这样的结果:
好多了。如果您真的受到限制,并且由于某些无法克服的原因无法将图放大,那么下一个最佳选择是仅打印指数并相应地调整轴标签。您可以使用\printonlyexponent
上面 MWE 中定义的方法。
补充几点:
- 我建议不要旋转 y 轴标签。这样阅读起来会困难得多。
- 您的 x 轴标签看起来不对。您可能指的是
\omega\,\si{\s\per\radian}
。