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 have this:

\begin{tikzpicture}
\begin{axis}[
ybar = 0.6,
width=1.2\textwidth,
height=0.4\textheight,
enlarge x limits = 0.2,
bar width=16pt,
title={Instance els19 with 1\% max error},
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=0},
ylabel={Time in milisseconds},
symbolic x coords={s-HAS, s-cAS, CUDA-HAS},
xtick=data,
nodes near coords,
%nodes near coords align={horizontal},
]
\addplot coordinates {(s-HAS,44.60) (s-cAS,71.90) (CUDA-HAS,8.67)};
\addplot coordinates {(s-HAS,4) (s-cAS,4) (CUDA-HAS,6)};
\addplot coordinates {(s-HAS,156) (s-cAS,334) (CUDA-HAS,18)};


\legend{Average 1\%,Best 1\%,Worst 1\%}
\end{axis}
\end{tikzpicture}

and this is generated:

enter image description here

Is there any way i could put the bar values that are currently above each bar inside the bar? The bars could be wider. Also, the number could be rotated 90 degrees.

I need this because on some other figures the numbers are really large, and they stay on top of each other, like this:

enter image description here

Also, any tip on how to make these charts look better is accepted.

share|improve this question
    
Thanks for the edit to make the images smaller ;) –  polar Mar 1 '12 at 18:08

1 Answer 1

up vote 11 down vote accepted

The numbers won't fit inside the bar with very small values (the red columns in your first example), so it's generally safer to keep them above. If you do want to place them inside the bars, you can set every node near coord/.append style={anchor=north}, which will use the top of the label nodes (the north anchor) for the placement. You can rotate the labels by adding the option rotate=90, anchor=east (to place them inside the columns) or anchor=west to place them on top.

For column charts like this, I would recommend setting ymin=0 to make sure that the columns start at 0, and enlarge y limits={upper, value=<value>} to only add space at the top of the plot.

For making the plots a bit more graphically appealing, there are a number of things you can do. For one, I would order the columns from smallest to largest. Based on How to minimize the ink-to-data ratio for pgfplots, here's a more reduced version of your chart. I've also increased the space between the legend entries as explained in How can I adjust the horizontal spacing between legend entries in PGFPlots?.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
compat=newest, %Better label placement
ybar = 0.6,
width=1.2\textwidth,
height=0.4\textheight,
enlarge y limits={upper, value=0.2},
ymin=0,
enlarge x limits = 0.2,
bar width=32pt,
title={Instance els19 with 1\% max error},
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=0},
ylabel={Time in milisseconds},
symbolic x coords={s-HAS, s-cAS, CUDA-HAS},
xtick=data,
nodes near coords,
axis lines*=left,
y axis line style={opacity=0},
yticklabels={\empty},
ytick style={draw=none},
cycle list={
    {fill=black!60,draw=black!60},
    {fill=black!40,draw=black!40},
    {fill=black!20,draw=black!20}
},
axis on top,
major grid style=white,
ymajorgrids,
legend style={draw=none,/tikz/every even column/.append style={column sep=0.5cm}}
%nodes near coords align={horizontal},
]
\addplot coordinates {(s-HAS,4) (s-cAS,4) (CUDA-HAS,6)};
\addplot coordinates {(s-HAS,44.60) (s-cAS,71.90) (CUDA-HAS,8.67)};
\addplot coordinates {(s-HAS,156) (s-cAS,334) (CUDA-HAS,18)};


\legend{Best 1\%,Average 1\%,Worst 1\%}
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
5  
+10 for color scheme;) –  Yiannis Lazarides Mar 1 '12 at 4:52
1  
Wow, this is beautiful. After I posted this question I found out how to rotate the numbers 90 degrees and it was fine, but this.. this is AWESOME. Thanks. –  polar Mar 1 '12 at 18:04

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.