0

I've to do a (simple) histogram using PGFPlots, but I don't know why it doesn't shows all the series on the X-Axis.

Minimal working example:

\begin{tikzpicture}
  \begin{axis}[
      x tick label style={
        /pgf/number format/1000 sep=},
      ylabel={\small{Efficienza (\milli\gram\per\gram)}},
      width = 15.4cm, height = 10.7cm,
      legend style={
        font=\scriptsize,
        cells={anchor=west}
      },
      legend pos=north west,
      symbolic x coords={Spugna 1,Spugna 2,Spugna 3,Spugna 4,Spugna 5,Spugna 6},
      xtick=data,
      tick label style={font=\scriptsize},
      ybar interval=0.7,
    ]
    \addplot coordinates {(Spugna 1,0.56) (Spugna 2,2.84) (Spugna 3,3.57) (Spugna 4,5.45) (Spugna 5,1.12) (Spugna 6,4.29)};
    \addplot coordinates {(Spugna 1,0.66) (Spugna 2,3.10) (Spugna 3,3.77) (Spugna 4,5.61) (Spugna 5,1.27) (Spugna 6,4.27)};
    \legend{Reali,Fitting}
  \end{axis}
 \end{tikzpicture}

There are clearly 6 series, but PGFPlots only show 5 of them:

Wrong plot with only 5 series

However, if I put ybar instead of ybar interval=0.7, all the series are typesetted (but in an ugly plot):

Correct plot but ugly bars

How can I fix that?

  • 1
    What do you think is ugly on the second image? I guess you mean the white space between the bars. To reduce that you can either change the bar width to a value that fits your needs or you can change the width of the axis environment. – Stefan Pinnow Sep 1 '17 at 16:31
  • @stefan-pinnow I will try it, thank you! – fratili Sep 1 '17 at 18:14
  • 2
    It doesn't show all the bars in the first one, because that is what ybar interval is designed to do, read the description of it in the pgfplots manual. – Torbjørn T. Sep 1 '17 at 19:27
2

I want to write a proper answer to this, for future reference.

It turns out that, actually, I wasn't unable to find the right thing in the ginormous PGFPlot manual :) so I've fixed it (thanks Stefan) using ybar and bar width = .8cm.

Solved! Correct histogram

Final code:

\begin{tikzpicture}
  \begin{axis}[
      x tick label style={
        /pgf/number format/1000 sep=},
      ylabel={\small{Efficienza (\milli\gram\per\gram)}},
      width = 15.4cm, height = 10.7cm,
      legend style={
        font=\scriptsize,
        cells={anchor=west}
      },
      legend pos=north west,
      symbolic x coords={Spugna 1,Spugna 2,Spugna 3,Spugna 4,Spugna 5,Spugna 6},
      xtick=data,
      tick label style={font=\scriptsize},
      ybar,
      bar width = .8cm
    ]
    \addplot coordinates {(Spugna 1,0.56) (Spugna 2,2.84) (Spugna 3,3.57) (Spugna 4,5.45) (Spugna 5,1.12) (Spugna 6,4.29)};
    \addplot coordinates {(Spugna 1,0.66) (Spugna 2,3.10) (Spugna 3,3.77) (Spugna 4,5.61) (Spugna 5,1.27) (Spugna 6,4.27)};
    \legend{Reali,Fitting}
  \end{axis}
 \end{tikzpicture}

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.