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'm plotting a ybar, and nodes near coords is ugly. Is it possible to rotate the text above the bars by 90?

\begin{tikzpicture}
\begin{axis}[area legend,
legend pos=north west,
legend columns=4,
legend style={draw=none},
symbolic x coords={D,F,R,M,K,S,C},
major tick length=0cm,
xtick=data,
nodes near coords,
ybar,
bar width = 6pt,
]
\addplot[area legend] %[ybar,,fill=blue]  fill=color1
coordinates {(D,0.78) (F,0.23) (R,0.93) (M,0.73) (K,0.00) (S,0.37) (C,0.36)};
\addplot[area legend] %[ybar,,fill=blue]
coordinates {(D,0.52) (F,0.62) (R,0.60) (M,0.56) (K,0.64) (S,0.166) (C,0.170)};
\addplot[area legend] %[ybar,,fill=blue]
coordinates {(D,0.635) (F,0.437) (R,0.744) (M,0.345) (K,0.48) (S,0.652) (C,0.955)};
\end{axis}
\end{tikzpicture}
share|improve this question
    
can you please provide a working example? otherwise it is difficult to give a good answer –  Martin H Jul 7 '11 at 11:56
    
done. If only I could rotate the text above the bars, it would save a lot of space. –  Iain Jul 7 '11 at 12:26
2  
Please always add a full, compilable minimal working example (MWE) that illustrates your problem, not just code fragments. It's just a few lines more (in most cases) and avoids confusion, potential errors and extra works for answerers. –  Martin Scharrer Jul 7 '11 at 13:09
add comment

2 Answers 2

up vote 8 down vote accepted

You can rotate the nodes using

every node near coord/.append style={rotate=90, anchor=west}

Note that this option needs to be added after ybar, since ybar overwrites the every node near coord style.

The nodes near coords do not automatically enlarge the plot area to accommodate them, so you have to do something like enlarge y limits={upper,value=0.2} to adjust the top border of the plot area.

(Unrequested extra information: The option area legend has to be passed to the addplots, it is not an axis option. To do this for all plots, you have to use the axis option every axis plot post/.style={area legend})

pgfplots with rotated labels

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    symbolic x coords={D,F,R,M,K,S,C},
    major tick length=0cm,
    xtick=data,
    enlarge y limits={upper,value=0.2},
    nodes near coords,
    ybar,
    every node near coord/.append style={rotate=90, anchor=west},
    bar width = 6pt,
]
\addplot
coordinates {(D,0.78) (F,0.23) (R,0.93) (M,0.73) (K,0.00) (S,0.37) (C,0.36)};
\addplot
coordinates {(D,0.52) (F,0.62) (R,0.60) (M,0.56) (K,0.64) (S,0.166) (C,0.170)};
\addplot
coordinates {(D,0.635) (F,0.437) (R,0.744) (M,0.345) (K,0.48) (S,0.652) (C,0.955)};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thats fantastic Jake. Works a treat. Thanks. –  Iain Jul 7 '11 at 13:10
add comment

You can use \rotatebox{<angle>}{Text} (from the already loaded graphicx) package to rotate text. More complicated stuff like verbatim text can be rotated using the {adjustbox}{angle=<angle>} environment provided by the adjustbox package. Simply use these macros inside the node, but TikZ might have own options for it.

share|improve this answer
    
Please reject my edit, it was a mistake –  Iain Jul 7 '11 at 12:27
    
I don't see how this helps, nodes near coord automatically generates the text. –  Iain Jul 7 '11 at 12:28
    
@Iain: In this case I misunderstood your question. –  Martin Scharrer Jul 7 '11 at 12:57
    
@Iain, @Martin: The general idea is definitely correct, the normal TikZ option rotate=90 doesn't work in this case. I've used Martin's approach in my answer. –  Jake Jul 7 '11 at 13:01
1  
@Ian: You are welcome. After it turned out that this was useful after all, it would be nice if you take the down-vote back (if its from you). Thanks. –  Martin Scharrer Jul 7 '11 at 13:16
show 2 more comments

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.