组图中无法识别条形宽度

组图中无法识别条形宽度

我正在尝试将四个条形图放在一个组图中。我的文件是

\documentclass[tikz,border=3pt]{standalone}
\usepackage{xcolor}
\usepackage{pgfplots,pgfplotstable}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.4}
\pgfplotsset{every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
\renewcommand{\rmdefault}{phv}
 % Arial font
\renewcommand{\sfdefault}{phv} 
% Arial font
\definecolor{MediumSeaGreen}{rgb}{0.235294,0.701961,0.443137}
\definecolor{gold}{rgb}{1.000000,0.843137,0.000000}
\definecolor{LightBlue}{rgb}{0.678431,0.847059,0.901961}\definecolor{LightGrey}{rgb}{0.827451,0.827451,0.827451}
\definecolor{DarkGrey}{rgb}{0.662745,0.662745,0.662745}\definecolor{DarkGrey}{rgb}{0.662745,0.662745,0.662745}
\makeatletter
\pgfplotsset{/pgfplots/flexible xticklabels from table/.code n args={3}{%
        \pgfplotstableread[#3]{#1}\coordinate@table
        \pgfplotstablegetcolumn{#2}\of{\coordinate@table}\to\pgfplots@xticklabels
        \let\pgfplots@xticklabel=\pgfplots@user@ticklabel@list@x}}
\makeatother
\pgfplotscreateplotcyclelist{mycolor}{
       {black,fill=MediumSeaGreen,mark=none},
    {black,fill=gold,mark=none},
    {black,fill=LightBlue,mark=none},
    {black,fill=LightGrey,mark=none},
}
%
\begin{document}
\color{DarkGrey}
\pgfplotsset{ tick label style = {font=\tiny}, every axis/.append style={font=\tiny}}
\begin{tikzpicture}
\pgfplotstableread[col sep=space,row sep=crcr]{data.txt}\mydata;
 \begin{groupplot}[
        group style={group size=2 by 2,vertical sep=1.5cm},
        width=8cm,
        height=5cm,  
        major x tick style = transparent,
     yticklabel={\ifdim\tick pt=0pt 0 \else\pgfmathprintnumber{\tick}\fi},
     y tick label style={/pgf/number format/fixed,/pgf/number format/precision=1,
     ylabel near ticks,
     yticklabel pos=left,
     /pgf/number format/fixed zerofill},
     ybar=0pt,
     cycle list name=mycolor,
        ymajorgrids=false,
        ylabel = {\%},   
     xtick={0,1,2,3,4,5,6,7,8,9,10,11},
     flexible xticklabels from table={data}{month}{col sep=space}, 
        x tick label style={rotate=270,anchor=west},
        scaled y ticks = false,
        enlarge x limits=0.05,
        ymin=0,
     ymax=.6]
%    
\nextgroupplot[legend to name=grouplegend,]
 \pgfplotsinvokeforeach {1,...,4}{\addplot[bar width=2pt] table [x expr={\coordindex}, y index=#1] {\mydata};}
% 
\nextgroupplot[legend to name=grouplegend,]
%
\pgfplotsinvokeforeach {1}{\addplot[bar width=2pt,color=black,fill=MediumSeaGreen] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {2}{\addplot[bar width=2pt,color=black,fill=gold] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {3}{\addplot[bar width=2pt,color=black,fill=LightBlue] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {4}{\addplot[bar width=2pt,color=black,fill=LightGrey] table [x expr={\coordindex}, y index=#1] {\mydata};}
%
\nextgroupplot
%
\pgfplotsinvokeforeach {1}{\addplot[bar width=2pt,color=black,fill=MediumSeaGreen] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {2}{\addplot[bar width=2pt,color=black,fill=gold] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {3}{\addplot[bar width=2pt,color=black,fill=LightBlue] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {4}{\addplot[bar width=2pt,color=black,fill=LightGrey] table [x expr={\coordindex}, y index=#1] {\mydata};}
%
\nextgroupplot[legend to name=grouplegend,]
%
\pgfplotsinvokeforeach {1}{\addplot[bar width=2pt,color=black,fill=MediumSeaGreen] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {2}{\addplot[bar width=2pt,color=black,fill=gold] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {3}{\addplot[bar width=2pt,color=black,fill=LightBlue] table [x expr={\coordindex}, y index=#1] {\mydata};}
\pgfplotsinvokeforeach {4}{\addplot[bar width=2pt,color=black,fill=LightGrey] table [x expr={\coordindex}, y index=#1] {\mydata};}
%
  \end{groupplot}
\end{tikzpicture}
\end{document}

数据输入文件是

month   a   b   c   d   
OCT'12  0.62    0.02    3.48    0.22
NOV'12  0.70    0.00    3.58    0.19
DEC'12  0.37    0.00    2.21    0.20
JAN'13  0.37    0.18    3.41    0.25
FEB'13  0.29    1.09    4.04    0.18
MAR'13  0.10    1.12    3.54    0.26    
APR'13  0.00    0.60    3.50    0.18
MAY'13  0.21    0.37    3.50    0.18
JUN'13  0.07    0.37    2.58    0.14
JUL'13  0.00    0.42    3.25    0.02
AUG'13  0.00    0.37    4.62    0.12
SEP'13  0.00    0.48    3.94    0.15

我的第一个问题是:如果我在以下括号内设置条形宽度,\begin{group plot}则会出错,因为条形宽度无法被组图识别,因此每当我调用组内的每个图时,我都必须设置该值。我的第二个问题与条形颜色有关,调用我在序言 ( \mycolor)中定义的颜色循环cycle list name=mycolor时,颜色无法被识别(查看左上角的图,所有条形都是白色的,我发现解决这个问题的简单方法是为每个条形调用每种颜色,就像我在其他三个图中所做的那样,我相信有一种最简单的方法可以做到这一点

答案1

关于您的第一个问题,您可以通过指定来设置bar width之后的。\begin{group plot}/pgf/bar width=2pt

关于你的第二个问题,你需要用(添加符号)替换你的\addplot[...]命令。使用,括号内的选项是\addplot+[...]+\addplot+[...]添加到 groupplot 样式中当前设置的选项,没有+它们代替这些选项。

相关内容