1

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}

enter image description here

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}
  • Take care when you add an image, that the code is deselected first. As you can see in your code, you have \[ and \] instead of [ and ] throughout the code, so would be nice if you could fix that. – Torbjørn T. Mar 6 '17 at 15:58
  • Duplicate: tex.stackexchange.com/questions/160869 I also edited your question and propose a possible MWE. – Dr. Manuel Kuehner Mar 6 '17 at 16:23
2

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 with shell-escape enabled, and without it you get an error. Note also that you load the color package twice, but pgfplots already loads xcolor, so that isn't really necessary.

\documentclass[a4paper, 12pt]{scrreprt}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.14,
every axis/.append style={grid, width=0.7\textwidth, height=5cm, tick label style ={font=\small}, label style={font=\scriptsize}, max space between ticks=35},
grid style={densely dotted},
}
\definecolor{amber}{rgb}{1.0, 0.75, 0.0}%
\definecolor{neuesrot}{RGB}{207, 103, 102}%

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=12cm,
    ymax=35,
    ymin=0,
    ybar,
    bar shift=0pt, % this must be after ybar to have effect
    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)(BGH\_0.8\_2.2\_160\_2.V,0)(BGH\_0.65\_2.2\_190\_2.V,0)(DEW\_0.65\_2.2\_160\_2.V,0)(DEW\_0.65\_2.2\_190\_2.V,0)};

        \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{document}

enter image description here

  • Very nice, sorry for the additional stuff. Won't happen again. – Jets3t Mar 6 '17 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.