组图中的数字格式有问题

组图中的数字格式有问题

这个问题已经回答了axis 这里但我在应用该方法时遇到了麻烦groupplots(请参阅%additional codeMWE)。如果我取消注释,%additional code代码可以正确编译,但数字格式不符合我的要求(千位分隔符 =.(或为空)和小数分隔符 =,)也许它们彼此无关,但我不明白为什么我会收到以下消息:

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

梅威瑟:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots} 

\begin{document}

\begin{figure}[htbp]
\label{fig:PlotDemand}
\centering
\begin{tikzpicture}
    \begin{groupplot}[

        group style={
            group size=2 by 2,
            vertical sep= 1.5cm,
            every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel}
        },
       /pgf/number format/.cd,%additional code
       use comma,%additional code
       1000 sep={},%additional code
        footnotesize,
        xtick={42,44,46,48}

]
    \nextgroupplot[title=\#1]
        \addplot[blue] coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432) (46, 972) (47, 540) (48, 1104) (49, 0)};
    \nextgroupplot[title=\#2]
        \addplot[blue] coordinates{(42, 400) (43, 400) (44, 0) (45, 400) (46, 0) (47, 0) (48, 0) (49, 0)};
    \nextgroupplot[title=\#3]
        \addplot[blue] coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900) (46, 2100) (47, 2100) (48, 2100) (49, 0)};
    \nextgroupplot[title=\#4]
        \addplot[blue] coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800) (46, 2000) (47, 2800) (48, 0) (49, 0)};
    \end{groupplot}
\end{tikzpicture}
\end{figure}


\end{document}

答案1

要使用空格作为千​​位分隔符,您需要将其添加到序言中:

\pgfkeys{/pgf/number format/.cd,%additional code
       use comma,%additional code
       1000 sep={\,},%additional code
}

这不应该是groupplot选项的一部分。如果您不想要空格,您可以使用1000 sep={}

如果您希望限制此设置的范围,可以在环境内完成tikzpicture

答案2

删除空行并稍微调整代码后,它确实起作用了……

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots} 

\begin{document}

\begin{figure}[htbp]
\label{fig:PlotDemand}
\centering
\begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=2 by 2,
            vertical sep= 1.5cm,
            every axis y label/.style={at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel}
        },
%       /pgf/number format/use comma,   % Solution 1
%       /pgf/number format/1000 sep={}, %
        yticklabel style={/pgf/number format/.cd,use comma, 1000 sep={}}, % Solution 2
%        every y tick label/.append style={/pgf/number format/.cd,use comma, 1000 sep={}}, % same as Solution 2
        footnotesize,
        xtick={42,44,46,48}
]
    \nextgroupplot[title=\#1]
        \addplot[blue] coordinates{(42, 255) (43, 1584) (44, 1296) (45, 432) (46, 972) (47, 540) (48, 1104) (49, 0)};
    \nextgroupplot[title=\#2]
        \addplot[blue] coordinates{(42, 400) (43, 400) (44, 0) (45, 400) (46, 0) (47, 0) (48, 0) (49, 0)};
    \nextgroupplot[title=\#3]
        \addplot[blue] coordinates{(42, 1800) (43, 2100) (44, 1800) (45, 900) (46, 2100) (47, 2100) (48, 2100) (49, 0)};
    \nextgroupplot[title=\#4]
        \addplot[blue] coordinates{(42, 6800) (43, 2800) (44, 2800) (45, 2800) (46, 2000) (47, 2800) (48, 0) (49, 0)};
    \end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}

相关内容