我想用一些标记或数字注释条形图以表明某些结果的重要性。重要性在与主值不同的列中给出。
仅举一个例子来说明我想做的事情:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotstableread{
1 10 0.84 50 0.75 10 0.22 30 0.24
2 40 0.38 60 0.96 15 0.42 90 0.28
3 20 0.42 60 0.42 15 0.24 60 0.86
}\mytable
\begin{document}%
\begin{tikzpicture}
\begin{axis}[
ybar,enlarge x limits=0.2,bar width=7pt,xtick={1,2,3,4}
]
\addplot table [x index=0,y index=1] {\mytable};
\addplot table [x index=0,y index=3] {\mytable};
\addplot table [x index=0,y index=5] {\mytable};
\addplot table [x index=0,y index=7] {\mytable};
\end{axis}
\end{tikzpicture}
% I would like to mark bars where adjacent value is greater than 0.95
% more specifically: column 2 for value 2
% I would also like to add a different mark where adjacent value is greater than 0.85 (but less than 0.95)
% more specifically: column 4 for value 3
\end{document}
确切的分数并不重要;这只是为了给出一个想法。
我知道nodes near coords
这里可能会有帮助,但我不知道如何从不同的系列中获得它。
(此外,对于我的图表的格式(以上只是一个例子),我认为我没有空间来提供实际值,相反,我可能希望将这些值转换为条形图上的某种标记。我知道这是一个不同的问题,所以我有兴趣关注第一个问题。)
答案1
这里建议使用point meta=explicit symbolic
、nodes near coords
和every node near coord/.append style
。
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\pgfplotstableread{
1 10 0.84 50 0.75 10 0.22 30 0.24
2 40 0.38 60 0.96 15 0.42 90 0.28
3 20 0.42 60 0.42 15 0.24 60 0.86
}\mytable
\begin{document}%
\begin{tikzpicture}
\begin{axis}[
ybar,enlarge x limits=0.2,bar width=7pt,xtick={1,2,3,4},
point meta=explicit symbolic,
nodes near coords={
\ifdim \pgfplotspointmeta pt > 0.95pt
\textcolor{green}{\huge$\bullet$}%
\else
\ifdim \pgfplotspointmeta pt > 0.85pt
\textcolor{green!50!blue!50}{\huge$\bullet$}%
\fi\fi
},
every node near coord/.append style={inner sep=0pt,anchor=center}
]
\addplot table [x index=0,y index=1,meta index=2] {\mytable};
\addplot table [x index=0,y index=3,meta index=4] {\mytable};
\addplot table [x index=0,y index=5,meta index=6] {\mytable};
\addplot table [x index=0,y index=7,meta index=8] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}
结果:
或
\begin{axis}[
ybar,enlarge x limits=0.2,bar width=7pt,xtick={1,2,3,4},
point meta=explicit symbolic,
nodes near coords={
\ifdim \pgfplotspointmeta pt > 0.95pt
\textcolor{green}{\huge$\star$}%
\else
\ifdim \pgfplotspointmeta pt > 0.85pt
\textcolor{green!50!blue!50}{\huge$\star$}%
\fi\fi
}
]