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.

The following figure has annoying x ticks at 0.5, 1.5 and 2.5. Non-integer values have no interpretation for my purpose.

Figure with ugly x-axis ticks

Question: How can I get pgfplots to exclude non-integer x-axis ticks?

I realise I could do this via xtick={0,...,3}, but in larger cases, say with xtick={0,...,100}, the ticks would overlap. So, this approach is not "flexible".

Ideally, I'd like to leave everything alone, except get rid of non-integer x-axis ticks if they arise.

Here's a minimum working example (it, of course, requires the standalone class and pgfplots package to run):

\documentclass[crop]{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[ybar=0,xlabel={$\lambda$},ylabel={$\#\{\prec:\Lambda(G,\prec)=\lambda\}$},ymin=0,height=2in,width=4in]
    \addplot[blue!50,bar width=0] coordinates {
      (0,2)
      (1,4)
      (2,6)
      (3,12)
    };
  \end{axis}
\end{tikzpicture}

\end{document}
share|improve this question
1  
Can you provide an MWE? I don't get the packages/tikz-subpackages that fast, that you are using, but i think, something like xtick={0,25,...,100}, i.e. the second number to specify the step width should work (and is flexible as requested). –  Ronny Feb 26 '13 at 17:37
1  
Added MWE; the above compiles on my computer. –  Douglas S. Stones Feb 26 '13 at 18:55
    
I missed (after a longish work day) the pgfplots in my first approach. –  Ronny Feb 26 '13 at 19:00

1 Answer 1

So I tried my approach mentioned in the comment, here's the MWE

\documentclass[a4paper,12pt]{scrartcl}
\usepackage{tikz,pgfplots,amsmath}
\begin{document}
    \begin{tikzpicture}
      \begin{axis}[xtick={0,1,...,3},ybar=0,xlabel={$\lambda$},ylabel={$\#\{\prec:\Lambda(G,\prec)=\lambda\}$},ymin=0,height=2in,width=4in]
        \addplot[blue!50,bar width=0] coordinates {
          (0,2)
          (1,4)
          (2,6)
          (3,12)
        };
      \end{axis}
    \end{tikzpicture}
\end{document}

Which produces

plot.

You can change the 1 in {0,1,...,3} into a 2 to get just 0 and 2 with ticks, which demonstrates that for your question concerning {0,...,100} something like {0,20,...,100} would be quite nice and works fine.

Edit: Just as a note, because it might be of interest for others. Of course that also works the other way around, so {0,.25,...,3} or {0,.5,...,3} enforces noninteger values, though the first one looks quite dense.

share|improve this answer
    
Glad you found a solution! It's always best to strip code down to a minimum. For images, you can use the standalone documentclass, and note that pgfplots loads tikz- do you need the amsmath package for your example? –  cmhughes Feb 26 '13 at 18:23
    
I wasn't sure, due to \lambda and \prec so i added that just to be sure. Of cource one could also use standalone I'll keep that in mind for next time. Sometimes I'm just leazy, and i had such an nMWE (nearly minimal, due to scrartcl) already opened in an editor ;) –  Ronny Feb 26 '13 at 18:26
    
Thanks for that; it is indeed a solution to the problem. It would mean, however, that I would need to compute an appropriate separation between ticks in other instances (finding the separation would be possible via experimentation). –  Douglas S. Stones Feb 26 '13 at 18:57
    
What would be better for your convenience? If you know the number of ticks (say \x) you could easily compute the stepsize. If you know neither - well that's what your example above does: Take something that fits nicely. Whether there is something, that ommits non-integers and takes itself something nicely - I don't know. –  Ronny Feb 26 '13 at 18:59

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.