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 would like to add a single bar to my chart, but without any value. Unfortunately when I skip adding proper value with label x in coordinates, it (bar with label x) disappears from chart.

\begin{tikzpicture}
\begin{axis}[
   width=\textwidth,
   ybar,
   enlargelimits=0.10,
   legend style={at={(0.5,-0.2)},
   anchor=north,legend columns=-1},
   symbolic x coords={A,B,C},
   xtick=data,
   nodes near coords,
   nodes near coords align={vertical},
   x tick label style={rotate=45,anchor=east},
   ]
  \addplot coordinates {(B,5) (C,7)};
\end{axis}
\end{tikzpicture}

In this example bar A (and label A) will not appear on the chart. Anybody knows how to put this x label to chart?

share|improve this question
    
I don't understand: Do you want just the x tick label A, or do you also want a bar at that position? If you do want a bar, what length should that bar have? –  Jake Jun 13 at 12:20
    
I want only x label for A, without any bar value (length=0). –  marcin Jun 13 at 13:10

2 Answers 2

up vote 4 down vote accepted

Here is a suggestion using

   symbolic x coords={A,B,C},
   xtick={A,B,C},
   xmin=A,
   ymin=0,
   enlarge y limits={0.1,upper},

enter image description here

Code:

\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
   width=\textwidth,
   ybar,
   enlargelimits=0.10,
   legend style={at={(0.5,-0.2)},
   anchor=north,legend columns=-1},
   symbolic x coords={A,B,C},
   xtick={A,B,C},
   xmin=A,
   ymin=0,
   enlarge y limits={0.1,upper},
   nodes near coords,
   nodes near coords align={vertical},
   x tick label style={rotate=45,anchor=east},
   ]
  \addplot coordinates {(B,5) (C,7)};
\end{axis}
\end{tikzpicture}
\end{document} 
share|improve this answer
    
Thanks! This is what I was looking for. For C bar works similarly (xmax=C,ymin=0). –  marcin Jun 13 at 15:20

Another one with testing value of the bar value and deciding to put the node near coord or not. In case you need it for some obscure reason. The test should have been easier but somehow ifthenelse is not overloaded in this context. The output is the same as above

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
   width=\textwidth,
   ybar,ymin=0,enlarge y limits=false,
   enlarge x limits=0.10,
   legend style={at={(0.5,-0.2)},
   anchor=north,legend columns=-1},
   symbolic x coords={A,B,C},
   xtick=data,
   nodes near coords*={%
     \pgfmathprintnumberto[fixed,assume math mode]{\pgfplotspointmeta}{\temp}%
     \ifnum\temp=0\else\pgfmathprintnumber{\pgfplotspointmeta}\fi%
   },
   nodes near coords align={vertical},
   x tick label style={rotate=45,anchor=east},
   ]
  \addplot coordinates {(A,0) (B,5) (C,7)};
\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.