给出以下代码片段:
\begin{frame}
\titlesub
\pgfplotsset{compat=1.9}
\centering
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
height=0.9\textheight,
ybar stacked,
ymin=0,
enlarge y limits={upper, value=0.2},
enlarge x limits = 0.2,
bar width = 1 cm,
legend style={at={(1.1, 1)},
anchor=north,legend columns=1},
ylabel={CPU time (s)},
symbolic x coords={Run 1, Run 2, Run 3, Reference},
xtick=data,
nodes near coords,
legend style={/tikz/every even column/.append style={column sep=0.5cm}}]
%nodes near coords align={horizontal},
]
\addplot [fill = POLIMIblue] coordinates {(Run 1, 426) (Run 2, 387) (Run 3, 446) (Reference, 614) };
\addplot [fill = col2] coordinates {(Run 1, 1182) (Run 2, 725) (Run 3, 1517) (Reference, 951) };
\legend{Setup, Solve}
\end{axis}
\end{tikzpicture}
\end{frame}
如何更改标签 426/387/446/614(白色)和标签 1182/725/1517/951(其他颜色)的颜色?
答案1
您可以使用every node near coord/.style={green}
。
\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\begin{frame}
\pgfplotsset{compat=1.9}
\centering
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
height=0.9\textheight,
ybar stacked,
ymin=0,
enlarge y limits={upper, value=0.2},
enlarge x limits = 0.2,
bar width = 1 cm,
legend style={at={(1.1, 1)},
anchor=north,legend columns=1},
ylabel={CPU time (s)},
symbolic x coords={Run 1, Run 2, Run 3, Reference},
xtick=data,
nodes near coords,
legend style={/tikz/every even column/.append style={column sep=0.5cm}}]
%nodes near coords align={horizontal},
]
\addplot [fill = blue,every node near coord/.style={white}] coordinates {(Run 1, 426) (Run 2, 387) (Run 3, 446) (Reference, 614) };
\addplot [fill = red,every node near coord/.style={green}] coordinates {(Run 1, 1182) (Run 2, 725) (Run 3, 1517) (Reference, 951) };
\legend{Setup, Solve}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}