仅更改 ybar 中一个图的属性

仅更改 ybar 中一个图的属性

抱歉,我确信这个问题有一个简单的答案,但我就是找不到!我所要做的就是关闭nodes near coords第二组数据(即红色数据)上的标签(我认为它们被称为)。

本质上,必须有一种方法来访问轴上仅一个数据集的属性?

顺便说一句,有没有办法在每组两列之间提供一些分隔,即使得每组之间的分隔大于组内的分隔。

提前致谢!

在此处输入图片描述

\begin{tikzpicture}
\begin{axis}[
    ybar,
    height=7cm,
    width=\textwidth,
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1},
    ylabel={Thousands of SHSs},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    x tick label style={rotate=45,anchor=east},
    /pgf/number format/.cd,
        use comma,
        1000 sep={},
    xmin=1996.5,
    xmax=2013.5,
    tick pos=left,
    axis lines=left
    ]
\addplot table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    12
2004    21
2005    28
2006    37
2007    70
2008    103
2009    170
2010    325
2011    470
2012    644
2013    901
};

\addplot table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    7.8
2004    14
2005    19
2006    28
2007    48
2008    76
2009    114
2010    201
2011    237
2012    264
2013    292
};
\end{axis}
\end{tikzpicture}

%ref is http://c1cleantechnicacom.wpengine.netdna-cdn.com/files/2011/12/SHSGrameenShakti-e1325237359995.gif

答案1

你可以加

nodes near coords=\empty

到情节。完整代码:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    ybar,
    height=7cm,
    width=\textwidth,
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1},
    ylabel={Thousands of SHSs},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
    x tick label style={rotate=45,anchor=east},
    /pgf/number format/.cd,
        use comma,
        1000 sep={},
    xmin=1996.5,
    xmax=2013.5,
    tick pos=left,
    axis lines=left
    ]
\addplot table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    12
2004    21
2005    28
2006    37
2007    70
2008    103
2009    170
2010    325
2011    470
2012    644
2013    901
};

\addplot+[nodes near coords=\empty] table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    7.8
2004    14
2005    19
2006    28
2007    48
2008    76
2009    114
2010    201
2011    237
2012    264
2013    292
};
\end{axis}
\end{tikzpicture}


\end{document}

在此处输入图片描述

或者,杰克提及他的评论,您可以nodes near coords只为第一个图添加:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    ybar,
    height=7cm,
    width=\textwidth,
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1},
    ylabel={Thousands of SHSs},
    xtick=data,
    nodes near coords align={vertical},
    x tick label style={rotate=45,anchor=east},
    /pgf/number format/.cd,
        use comma,
        1000 sep={},
    xmin=1996.5,
    xmax=2013.5,
    tick pos=left,
    axis lines=left
    ]
\addplot+[nodes near coords] table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    12
2004    21
2005    28
2006    37
2007    70
2008    103
2009    170
2010    325
2011    470
2012    644
2013    901
};

\addplot table {
1997    0.2
1998    0.4
1999    1.2
2000    1.7
2001    3.2
2002    4.7
2003    7.8
2004    14
2005    19
2006    28
2007    48
2008    76
2009    114
2010    201
2011    237
2012    264
2013    292
};
\end{axis}
\end{tikzpicture}

\end{document}

相关内容