使用符号 x 坐标选项选择条形尺寸

使用符号 x 坐标选项选择条形尺寸

当我同时使用“条宽”和“符号 x”时,pdflatex 给我以下错误消息:

!软件包 pgfkeys 错误:我不知道密钥“/pgfplots/bar width”,我将忽略它。也许您拼错了。

您知道我如何使用“符号 x”选项来选择条形大小吗?

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\pgfplotsset{
    compat=newest,
    ybar stacked,
    symbolic x coords={val1,val2,val3},
    %bar width=1,% doest not work
}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot[black!40,pattern=north west lines, pattern color=blue] coordinates
{(val1,36.8539)  (val2,33.7547)      (val3,13.7547)};
        \addplot[black!40,pattern=north west lines, pattern color=red]  coordinates
{(val1,13.47)    (val2,12.7187)          (val3,22.7187)};
    \end{axis}
\end{tikzpicture}
\end{document}

答案1

您位于pgfplotsset设置pgfplots键的范围内。条形宽度是 PGF 键。如果在 pgfplots 系列中找不到键,您可以向轴提供选项,其中还尝试了 PGF 键系列。

如果您想多次使用这些选项,您可以将其保存在样式中并提供给每个轴,或者您也可以通过来设置它\pgfkeys{/pgf/bar width=2cm}。或者您可以为该键创建一个别名。有趣的是,这确实是一个 PGF 键。

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[ybar stacked,symbolic x coords={val1,val2,val3},bar width=1cm,xtick=data,enlarge x limits={abs=1.5cm}]
        \addplot[black!40,pattern=north west lines, pattern color=blue] coordinates
{(val1,36.8539)(val2,33.7547)(val3,13.7547)};
        \addplot[black!40,pattern=north west lines, pattern color=red]  coordinates
{(val1,13.47)(val2,12.7187)(val3,22.7187)};
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容