![Pgfplots 网格不显示](https://linux22.com/image/292053/Pgfplots%20%E7%BD%91%E6%A0%BC%E4%B8%8D%E6%98%BE%E7%A4%BA.png)
我在使用 为此图设置网格 时遇到了麻烦pgfplots
。
这是我的代码。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
/pgf/declare function = {
signal = 0.8 * (sin(deg(x)) + 0.7*sin(2*deg(x)) + 0.7*sin(3*deg(x)));
}
]
\begin{axis}[
grid = minor,
height= 0.35\textwidth,
width = 0.8\textwidth,
thick,
scale=1.8,
axis lines=center,
domain=0:20*pi,
samples=500,
line join=bevel,
xlabel=t,
ymax=2.7,
ymin=-2.7,
xmax=25.9,
xmin=0,
xtick=\empty,
ytick=\empty,
]
\addplot[ultra thick,black!40!cyan] { signal };
\end{axis}
\end{tikzpicture}
\end{document}
这个问题和轴线的设置有关系吗?
答案1
如果您想查看网格,请不要说xtick=\empty
and/or ytick=\empty
。使用xticklabels=\empty
andyticklabels=\empty
不显示ticklabels
,使用major thick length=0
andminor thick length=0
不显示刻度。
您只想查看次要网格?还是两者都要查看?对于次要网格,您必须设置minor tick num
。在下面的示例中,我同时使用 和 ,minor thick num=3
并将颜色设为major grid
红色。
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
/pgf/declare function = {
signal = 0.8 * (sin(deg(x)) + 0.7*sin(2*deg(x)) + 0.7*sin(3*deg(x)));
}
]
\begin{axis}[
grid = both,
minor tick num=3,
every major grid/.style={red, opacity=0.5},
height= 0.35\textwidth,
width = 0.8\textwidth,
thick,
scale=1.8,
axis lines=center,
domain=0:20*pi,
samples=500,
line join=bevel,
xlabel=t,
ymax=2.7,
ymin=-2.7,
xmax=25.9,
xmin=0,
xticklabels=\empty,
yticklabels=\empty,
major tick length=0pt,
minor tick length=0pt,
%xtick=\empty,
%ytick=\empty,
]
\addplot[ultra thick,black!40!cyan] { signal };
\end{axis}
\end{tikzpicture}
\end{document}