# How to omit non-integer x-axis ticks in pgfplots?

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

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]
(0,2)
(1,4)
(2,6)
(3,12)
};
\end{axis}
\end{tikzpicture}

\end{document}

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

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]
(0,2)
(1,4)
(2,6)
(3,12)
};
\end{axis}
\end{tikzpicture}
\end{document}


Which produces

.

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.

-
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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.850594699382782, "perplexity": 1846.0233801141212}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-27/segments/1435375097710.32/warc/CC-MAIN-20150627031817-00014-ip-10-179-60-89.ec2.internal.warc.gz"}