6

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}
  • So you want a bunch of parallel horizontal lines? If that is the case, use \foreach – dustin Sep 2 '13 at 3:33
8

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

  • How can we place the tikz figure surrounded by text? – Eden Harder Sep 2 '13 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. – Gonzalo Medina Sep 2 '13 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.