1

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)};    \end{axis}    \end{tikzpicture}

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 likethose values to appear (i.e. 0.13, 0.191, 0.252, and so on) instead.
I have tried definingxmin andxmax values and definig the xbar interval, but nothing seems to work. I would really appreciate any help.

askedJun 23, 2020 at 1:19
Sebas Palacios's user avatar
1
  • 1
    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.CommentedJun 23, 2020 at 6:47

1 Answer1

2

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

% used PGFPlots v1.17\documentclass[border=5pt]{standalone}\usepackage{pgfplots}\begin{document}\begin{tikzpicture}    \begin{axis}[        ymin=0,        ymax=30,        % show ticks at the data points        xtick=data,        % ---------------------------------------------------------------------        % (adapt the tick label style to see all three decimal digits)        x tick label style={            rotate=90,            /pgf/number format/.cd,                precision=3,                zerofill,        },        % ---------------------------------------------------------------------        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)        };    \end{axis}\end{tikzpicture}\end{document}

image showing the result of above code

answeredJun 23, 2020 at 6:55
Stefan Pinnow's user avatar

You mustlog in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.