7

How can we only plot grid in X direction? Could we change "grid=both" to "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
  • So you want a bunch of parallel horizontal lines? If that is the case, use \foreach
    – dustin
    Sep 2, 2013 at 3:33

1 Answer 1

11

You have the keys xmajorgrids, xminorgrids, ymajorgrids, yminorgrids:

\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}

enter image description here

2
  • How can we place the tikz figure surrounded by text? Sep 2, 2013 at 4:21
  • 1
    @EdenHarder Do you mean that the text wraps around the figure? If so, take a look at the wrapfig package; of not, please explain in more detail your intent. Sep 2, 2013 at 4:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .