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.

I'm doing a histogram with a large number of bins:

\pgfplotstableset{col sep=semicolon}
\begin{tikzpicture}
  \begin{axis}[
    ybar interval,
  ]
    \addplot+[hist={bins=200}] table[y index=0] {FILENAME};
  \end{axis}
\end{tikzpicture}

Unfortunately, pgfplots produces a terribly ugly x-axis where the xticks are printed too close together so that they are overlapping and you can't read a thing.

How can I reduce the number of ticks? For example show only every nth tick.

share|improve this question
    
You can specify where exactly you want the ticks to go with xtick={-20,-15,...,20} or some other pattern. Please keep in mind that while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Without a sample of FILENAME the reproduces this I can not test if this will fix the problem for you. –  Peter Grill Apr 10 '12 at 4:51
    
Related: tex.stackexchange.com/questions/47345/… –  Torbjørn T. Apr 10 '12 at 4:56
    
xtick doesn't help because the numbers I have are quite high precision: pastebin.com/h68WDRZY –  Fabian Apr 10 '12 at 5:16
1  
So how many significant digits do you want to display? I think the results with xtick={0,2,...,12} with your data produces reasonable results, but perhaps a real expert with plotting will have a better answer for you. –  Peter Grill Apr 10 '12 at 6:52
add comment

1 Answer

up vote 6 down vote accepted

For a histogram with such a large number of bins, ybar interval as an axis option is not the ideal choice. ybar interval, if passed to the axis, will place a label for each bin, and draw a vertical line between each pair of bins; the algorithm usually employed for finding a useful number of labels is not used here. In your case, simply omitting ybar interval (or supplying ybar instead) in the axis options yields a much better result. Note that the ybar interval style is set for the individual plot anyway because you're using hist, but as a plot option, it doesn't influence the label placement:

The plot could be improved a bit by adding vertical grid lines, and choosing hist/data min, hist/data max, and hist/bins in such a way that the bins line up with the grid lines:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\pgfplotstableset{col sep=semicolon}
\begin{tikzpicture}
  \begin{axis}[
    enlarge x limits=false,
    enlarge y limits=upper,
    axis lines*=left,
    xmajorgrids,
    grid style={white,ultra thin},
    axis on top,
    tick align=outside
  ]
    \addplot [
        hist={bins=150, data min=0, data max=15},
        fill=black!75, draw=none
    ] table [y index=0] {data.csv};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
thanks! I was wondering about the strange labeling as well.. –  Fabian Apr 13 '12 at 11:43
add comment

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.