I'm very, very happy with pgfplots and using the ybar-plot-function to create a lot of diagrams. At the moment I wonders if it is possible to mark a missing value, for example with an asterisk. As you can see in the following example, one can easily identify a value of zero, but the missed values are not easy to identify. I would like to mark these empty ybars (in the example at M3, J4, J3) with an asterisk. Does anyone know how to automate or realize that?
\documentclass[
a4paper,%
headings=small,%
]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepgflibrary{shapes.geometric}
\usetikzlibrary{patterns,arrows}
\pgfplotsset{%
compat=newest,
every axis legend/.append style={draw=none, font=\scriptsize, column sep=5pt},
ymajorgrids=true,
/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={%
\draw[##1,/tikz/.cd, bar width=6pt, yshift=-0.25em, bar shift=0pt, xshift=0.8em]
plot coordinates {(0cm,0.8em)};},
},
/pgfplots/line legend/.style={
/pgfplots/legend image code/.code={%
\draw[mark repeat=2,mark phase=2,##1]
plot coordinates {(0cm,0cm) (0.3cm,0cm)(0.6cm,0cm)};},
}
}
\begin{document}
\begin{figure}[htb]
\centering
\footnotesize
\begin{tikzpicture}
\begin{axis}[
symbolic x coords={M6,M5,J2,M4,M1,M3,J1,M2,J4,J5,J3},
width=15cm,
height=5cm,
ylabel=Prozent,
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
ybar,
ymin=0,
ymax=100,
enlarge x limits=0.07,
enlarge y limits=0.07
]
\addlegendentry{FS}
\addplot [pattern=north east lines, ybar legend] coordinates {(M6,0) (M5,100) (J2,42.1) (M4,16.7) (M1,0) (M3,100) (J1,100) (M2,100) (J4,) (J5,0) (J3,0)};
\addlegendentry{IS}
\addplot [color=black, fill=lightgray, ybar legend] coordinates {(M6,20) (M5,50) (J2,58.2) (M4,50) (M1,0) (M3,) (J1,100) (M2,100) (J4,100) (J5,100) (J3,)};
\addlegendentry{\=x FS}
\addplot [black, sharp plot, update limits=false, line width = 1pt, line legend] coordinates {(M6,45.9) (J3,45.9)};
\addlegendentry{\=x IS}
\addplot [black, dashed, sharp plot, update limits=false, line width = 1pt, line legend] coordinates {(M6,64.2) (J3,64.2)};
\end{axis}
\end{tikzpicture}
\caption{Variable A: Intersituative Variantenrealisierung}
\end{figure}
\end{document}
Best Answer
You can do this with a
filter point
code. I've defined a new stylehighlight missing data
that interprets data points with a value of-1
as missing data and does a bit of work to position a node with an asterisk in the right place before replacing the value withnan
, which causes PGFplots not to draw a column for this value. You can change the value to be replaced by callinghighlight missing data=<value>
, maybe to-9999
or some other value that will definitely not appear in your real data. This code should work independently of the width of the bars or the number of series, but it won't work with horizontal bars at the moment (it could be adjusted to do that, however).