I'm trying to produce a y bar plot, that sometimes has data and sometimes doesn't. Yet, it has two plots and needs to get them right next to each other. Here is as close as I was able to get:
As you can see, the x ticks for the last four entries don't show up. Any idea why?
\documentclass[a4paper, 12pt]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{scrlayer-scrpage}
\usepackage{color}
\usepackage{pgfplots}
\usetikzlibrary{spy, pgfplots.statistics}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot, external, statistics}
\tikzexternalize
\pgfplotsset{
boxplot/every average/.style={%
/tikz/mark=diamond*,
},
compat=1.14,
grid style={densely dotted},
every legend/.append style={
pos={outer north east},
font={\scriptsize}},
}
\usepackage{color}
\definecolor{amber}{rgb}{1.0, 0.75, 0.0}%
\definecolor{bluegray}{RGB}{1, 171, 170}%
\definecolor{neuesrot}{RGB}{207, 103, 102}%
\definecolor{ultramarin}{RGB}{40, 109, 168}%
\definecolor{grauu}{RGB}{29, 39, 49}%
\definecolor{hellesgrau}{RGB}{216, 216, 216}%
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[width=12cm, bar shift=0pt, ymax=35, ymin=0,ybar, x tick label style={font=\tiny,rotate=75,anchor=east,}, xtick=data, symbolic x coords={BGH\_0.65\_160,BGH\_0.65\_190,BGH\_0.8\_160,BGH\_0.8\_190,BGH2\_0.65\_1\_190,BGH2\_0.65\_1\_160,BGH2\_0.8\_1\_190, BGH2\_0.8\_1\_160,DEW\_0.65\_160,DEW\_0.65\_190,DEW\_0.8\_160,DEW\_0.8\_190,BGH\_0.8\_2.2\_160\_2.V,BGH\_0.65\_2.2\_190\_2.V,DEW\_0.65\_2.2\_160\_2.V, DEW\_0.65\_2.2\_190\_2.V}]
\addplot [color=amber, fill=amber]coordinates {(BGH\_0.65\_160,22)(BGH\_0.65\_190,23)(BGH\_0.8\_160,10)(BGH\_0.8\_190,9)(BGH2\_0.65\_1\_190,14)(BGH2\_0.65\_1\_160,12)(BGH2\_0.8\_1\_190,14)(BGH2\_0.8\_1\_160,10)(DEW\_0.65\_160,30)(DEW\_0.65\_190,31)(DEW\_0.8\_160,15)(DEW\_0.8\_190,19)};
\addplot [color=neuesrot, fill=neuesrot]coordinates {(BGH\_0.65\_160,3)(BGH\_0.65\_190,4)(BGH\_0.8\_160,8)(BGH\_0.8\_190,3)(DEW\_0.65\_160,6) (DEW\_0.65\_190,6) (DEW\_0.8\_160,5) (DEW\_0.8\_190,6)(BGH\_0.8\_2.2\_160\_2.V,2)(BGH\_0.65\_2.2\_190\_2.V,2)(DEW\_0.65\_2.2\_160\_2.V,3)(DEW\_0.65\_2.2\_190\_2.V,3)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Edit by Manuel — Possible MWE
\documentclass[tikz]{standalone}
\usepackage{color}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymax=5,
ymin=0,
ybar,
xtick=data,
enlargelimits=true,
symbolic x coords=
{
A,
B,
C,
}
]
\addplot[color=red, fill=red] coordinates
{
(A,1)
(B,2)
};
\addplot [color=blue, fill=blue]coordinates
{
(B,2)
(C,2)
};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
xtick=data
only reads the data from the first\addplot
it seems. A workaround is to add zero-values for the four missing data points in the first plot.Code below, after removing the unused stuff from your example.
\tikzexternalize
in particular is unwanted, as I don't usually compile withshell-escape
enabled, and without it you get an error. Note also that you load thecolor
package twice, butpgfplots
already loadsxcolor
, so that isn't really necessary.