I'm trying to make a bar chart with really small x-increments. I used this code:

    \begin{axis}[ymin=0, ymax=30, minor y tick num = 5, area style,]
    \addplot+[ybar interval,mark=no] plot coordinates { (0.13, 15) (0.191, 17) (0.252, 26) (0.313, 3) 
    (0.374, 3) (0.435, 3) (0.496, 5) (0.56, 0)};

Which produced this picture:

enter image description here

The problem is that the numbers that appear under the x-axis have nothing to do with the numbers I want to plot. I think the bars are in place, it's just that the numbers that show up are 0.1, 0.2, 0.3, etc. but my plot starts at 0.13 and has increments of 0.061 . I would like those values to appear (i.e. 0.13, 0.191, 0.252, and so on) instead.
I have tried defining xmin and xmax values and definig the xbar interval, but nothing seems to work. I would really appreciate any help.

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Stefan Pinnow Jun 23 at 6:47

To achieve what you want you just need to add xtick=data to the axis options. To show more than two decimal places you need in addition to adapt the x tick label style. For details please have a look at the comments in the code.

% used PGFPlots v1.17
        % show ticks at the data points
        % ---------------------------------------------------------------------
        % (adapt the tick label style to see all three decimal digits)
        x tick label style={
            /pgf/number format/.cd,
        % ---------------------------------------------------------------------
        minor y tick num = 5,
        area style,
        \addplot+[ybar interval]  coordinates {
            (0.13,15) (0.191,17) (0.252,26) (0.313,3)
            (0.374,3) (0.435,3)  (0.496,5)  (0.56,0)

image showing the result of above code

| improve this answer | |

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.