当标签在 0:0.125:...:2 之间均匀分布时,是否有一种有效的方法来控制 tikiz 电路的标签,我想在 x 轴上显示数字 0,0.125,..2
\documentclass[border=1cm]{standalone}
\usepackage{amsmath}
\usepackage[siunitx]{circuitikz}
\usetikzlibrary{angles, arrows.meta,quotes}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
minor tick num=17,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
enlargelimits={abs=0.2},
xmin = 0, xmax = 2,
ymin = -1, ymax = 7,
xtick={0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1}
xticklabels={$0$,$0.125$,$0.25$,$0.375$,$0.5$,$0.625$,$0.75$,$0.875$,$1$}
]
\addplot[domain=0:2,samples=50,smooth,red] {4*cos(deg(2*pi*x-2*pi*0.125))+3};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
- 标签中使用的字体大小应该减小
- 数字精度必须提高(从默认值)2 到 3 位小数
- 图像应足够宽,以使标签不会重叠
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
axis lines=middle,
grid=both,
minor tick num=4,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
enlargelimits={abs=0.2},
xmin = 0, xmax = 2,
ymin = -1, ymax = 7,
xtick={0,0.125,...,2},
x tick label style={font=\scriptsize,
/pgf/number format/precision=3}
]
\addplot[domain=0:2,samples=50,smooth,red] {4*cos(deg(2*pi*x-2*pi*0.125))+3};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:
如果您可以接受旋转xtick
标签,例如 45 度,则可以增加xtick
标签中使用的字体大小。在这种情况下,x 刻度标签样式为:
x tick label style={font=\small, rotate=45, anchor=east,
/pgf/number format/precision=3,}
得到的图像为: