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've done my first bar chart with pgfplots and it looks like this:

bar chart

As you can see the first and the last bar are not completely visible and things got even worse when I tried to add another plot. How can I insert a horizontal space between the y-axis and these bars or make these bars completely visible by any other means?

The chart was generated by pdflatex with:

\begin{tikzpicture}
\begin{axis}
[
    symbolic x coords={36,72,144,288,576},
    xtick=data,
    ylabel=Time in Seconds,
    every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},
    xlabel=Memory in MB,
    every axis x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
    legend style={at={(0.5,-0.25)},
    anchor=north,legend columns=-1},
    ybar,
    bar width=7pt,
]
\addplot
coordinates {(36,1051.6) (72,875.0) (144,1099.3) (288,1114.6) (576,1054.3)};
\addplot
coordinates {(36,797.3) (72,717.6) (144,608.3) (288,591.6) (576,544.3)};
\addplot
coordinates {(36,735.3) (72,590.3) (144,533.6) (288,500.6) (576,447.0)};
\addplot
coordinates {(36,685.3) (72,544.0) (144,477.0) (288,451.6)(576,430.0)};
\legend{\,1 CPU\hspace*{0.5cm},\,2 CPUs\hspace*{0.5cm},\,3 CPUs\hspace*{0.5cm},\,4 CPUs}
\end{axis}
\end{tikzpicture}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can use the key enlarge x limits=<factor> to add extra space on the sides. enlarge x limits=0.15 combined with ybar=0.6pt works quite well:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
    symbolic x coords={36,72,144,288,576},
    xtick=data,
    ylabel=Time in Seconds,
    every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},
    xlabel=Memory in MB,
    every axis x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
    legend style={at={(0.5,-0.25)},
    anchor=north,legend columns=-1},
    ybar,
    bar width=6pt,
    enlarge x limits=0.15
]
\addplot
coordinates {(36,1051.6) (72,875.0) (144,1099.3) (288,1114.6) (576,1054.3)};
\addplot
coordinates {(36,797.3) (72,717.6) (144,608.3) (288,591.6) (576,544.3)};
\addplot
coordinates {(36,735.3) (72,590.3) (144,533.6) (288,500.6) (576,447.0)};
\addplot
coordinates {(36,685.3) (72,544.0) (144,477.0) (288,451.6)(576,430.0)};
\legend{\,1 CPU\hspace*{0.5cm},\,2 CPUs\hspace*{0.5cm},\,3 CPUs\hspace*{0.5cm},\,4 CPUs}
\end{axis}
\end{tikzpicture}

\end{document}

share|improve this answer

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.