Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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