我们如何才能只在 X 方向绘制网格?

我们如何才能只在 X 方向绘制网格?

我们如何才能只在 X 方向绘制网格?我们可以将“grid=both”更改为“grid=...”吗?

\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  grid=both,
  domain=0:2*pi,
  samples=200,
  no marks,
  xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
  xtick={-6.2832,-4.7124,...,6.2832},
  x post scale=1.5,
  ytick={-3,-2,-1,...,2,3},
  ymax=3]
 \addplot {(2*cos(\x r)- cos(2*\x r))} node[below, green] {$K_3$};
 \addplot {(3*cos(\x r)- cos(3*\x r))} node[below, green] {$K_4$};
\end{axis}
\end{tikzpicture}

答案1

您有钥匙xmajorgrids,,,:xminorgridsymajorgridsyminorgrids

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  xmajorgrids=true,
  domain=0:2*pi,
  samples=200,
  no marks,
  xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
  xtick={-6.2832,-4.7124,...,6.2832},
  x post scale=1.5,
  ytick={-3,-2,-1,...,2,3},
  ymax=3]
 \addplot {(2*cos(\x r)- cos(2*\x r))} node[below, green] {$K_3$};
 \addplot {(3*cos(\x r)- cos(3*\x r))} node[below, green] {$K_4$};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}[scale=0.8]
\begin{axis}[
  ymajorgrids=true,
  domain=0:2*pi,
  samples=200,
  no marks,
  xticklabels={-2$\pi$,-1.5$\pi$,...$\pi$,2$\pi$},
  xtick={-6.2832,-4.7124,...,6.2832},
  x post scale=1.5,
  ytick={-3,-2,-1,...,2,3},
  ymax=3]
 \addplot {(2*cos(\x r)- cos(2*\x r))} node[below, green] {$K_3$};
 \addplot {(3*cos(\x r)- cos(3*\x r))} node[below, green] {$K_4$};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容