如何从 ybar 图表中删除小值标签?

如何从 ybar 图表中删除小值标签?

我无法找到一种方法来防止标签中显示较小的值。与我的问题非常相似的问题可以在这里。由于我缺乏编码技能,我无法自己解决这个问题。以下是我目前得到的代码:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\definecolor{RYB1}{RGB}{128, 177, 211}
\definecolor{RYB2}{RGB}{251, 128, 114}
\definecolor{RYB3}{RGB}{190, 186, 218}
\definecolor{RYB4}{RGB}{255, 255, 179}
\definecolor{RYB5}{RGB}{141, 211, 199}
\definecolor{RYB6}{RGB}{253, 180, 98}

\pgfplotscreateplotcyclelist{ColorListBar}{
{RYB1!50!black,fill=RYB1},
{RYB2!50!black,fill=RYB2},
{RYB3!50!black,fill=RYB3},
{RYB4!50!black,fill=RYB4},
{RYB5!50!black,fill=RYB5},
{RYB6!50!black,fill=RYB6},
}

\begin{document}

    \begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\pgfkeys{
     /pgf/number format/precision=2, 
    /pgf/number format/fixed zerofill=true,
    /pgf/number format/fixed
}
\begin{axis}[
ybar stacked,
bar width=9mm,
nodes near coords,
enlargelimits=0.3,
legend style={at={(0.5,-0.20)},
anchor=north,legend columns=-1},
ylabel={ylabel},
symbolic x coords={A, B, C},
xtick=data,
cycle list name=ColorListBar
]
\addplot plot coordinates {(A,0.26) (B,0.32) (C,0.32)};
\addplot plot coordinates {(A,0.28) (B,0.29) (C,0.35)};
\addplot plot coordinates {(A,0.05) (B,0) (C,0.01)};
\addplot plot coordinates {(A,0.13) (B,0.17) (C,0.17)};
\addplot plot coordinates {(A,0.06) (B,0.01) (C,0.01)};
\addplot plot coordinates {(A,0.05) (B,0.07) (C,0.01)};
\legend{1, 2, 3, 4, 5, 6}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document} 

得到的图如下所示: 在此处输入图片描述

我想删除当前值为 0.01 的标签,因为这些标签看起来非常混乱。如何实现?

答案1

这实际上是同一个问题,但这是你的版本,

您还可以应用以下nodes near coords测试

nodes near coords = {%
    \pgfmathprintnumberto[fixed,assume math mode=true]{\pgfplotspointmeta}{\myval}%
    \pgfmathparse{\myval<0.05?:\myval}\pgfmathresult%
}

在此处输入图片描述

相关内容