1

This is the result so far:

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
    ybar,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
        anchor=north,legend columns=-1},
    ylabel={\#mountainbikes},
    symbolic x coords={April, Mai, Juni, Juli, August},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    ]
    \addplot+[ybar] plot coordinates {(April,0.36)};
    \addplot+[ybar] plot coordinates {(Mai,0.4)};
    \addplot+[ybar] plot coordinates {(Juni,0.5)};
    \addplot+[ybar] plot coordinates {(Juli,0.55)};
    \addplot+[ybar] plot coordinates {(August,0.52)};   
    \legend{\strut April, \strut Mai, \strut Juni, \strut Juli, \strut August}
    \end{axis}
\end{tikzpicture}
\end{document}

What I need help with: the x axis.

4
  • What do you mean by "fit all bars on x axis"?
    – user78499
    Sep 20, 2020 at 1:07
  • @Roboticist as you can see on the pic: the x-axis label is only complete for April but not for the other months. And the very left and the very right bar are not on entirely in the picture (only like a third of them are shown).
    – Kuroi Ryū
    Sep 20, 2020 at 1:39
  • Your code does not generate the image you have uploaded and returns some errors. Please supply an MWE.
    – user78499
    Sep 20, 2020 at 1:49
  • Manually set a larger enlargelimits, for example enlargelimits=.6. Sep 20, 2020 at 2:09

1 Answer 1

1

With pgfplots such diagrams are ussuall drawn as follows:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17,   % the last version at time of the answer
             width=7cm}

\begin{document}

    \begin{tikzpicture}
\begin{axis}[
    ybar,
    bar width = 4mm,              
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
                  anchor=north,legend columns=-1},
    ylabel={\#mountainbikes},
    symbolic x coords={April, Mai, Juni, Juli, August},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    nodes near coords style={/pgf/number format/.cd, fixed, precision=2,
                             /tikz/.cd, font=\scriptsize},
    ]
\addplot    coordinates {(April,0.36) (Mai,0.4) (Juni,0.5) (Juli,0.55) (August,0.52)};
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

If you like different colors for each month, than one possible solution using pgfplots package is make \xtick empty and instead them use \legend:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17,  
             width=7cm}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    ybar,
    bar width = 4mm,             
    enlarge x limits=0.8,
    legend style={at={(0.5,-0.05)},
                  anchor=north,legend columns=-1,
                  /tikz/every even column/.append style={column sep=3pt},
                  /tikz/.cd, font=\footnotesize},
    ylabel={\#mountainbikes},
    xtick=\empty,
    nodes near coords,
    nodes near coords align={vertical},
    nodes near coords style={/pgf/number format/.cd, fixed, precision=2,
                             /tikz/.cd, font=\scriptsize},
    ]
\addplot    coordinates {(1,0.36)};
\addplot    coordinates {(2,0.4)};
\addplot    coordinates {(3,0.5)};
\addplot    coordinates {(4,0.55)};
\addplot    coordinates {(5,0.52)};
    \legend{April, Mai, Juni, Juli, August}
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

2
  • Is the color sequence previously set or automated in the latter case?
    – user9424
    Sep 21, 2020 at 10:51
  • @BlackBird, used are default colors. You can overwrite them with color=... in each \addtplot or define own list of used colors.
    – Zarko
    Sep 21, 2020 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .