y-bar、符号 x 坐标未显示

y-bar、符号 x 坐标未显示

我正在尝试制作一个条形图,有时有数据,有时没有。但是,它有两个图,需要将它们并排放置。这是我能得到的最接近的结果:

如您所见,最后四个条目的 x 标记未显示。知道原因吗?

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

在此处输入图片描述

由 Manuel 编辑——可能是 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}

答案1

xtick=data似乎只读取第一个数据\addplot。解决方法是为第一个图中的四个缺失数据点添加零值。

下面的代码,在从示例中删除未使用的内容后。\tikzexternalize特别是不需要的,因为我通常不使用启用编译shell-escape,如果没有它,您会得到一个错误。还请注意,您加载了color两次包,但pgfplots已经加载了xcolor,所以这不是真正必要的。

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

在此处输入图片描述

相关内容