更改“ybar stacked”和“nodes near coords”的值的字体颜色

更改“ybar stacked”和“nodes near coords”的值的字体颜色

我不知道该如何更改堆叠条形图值的字体颜色。目前它使用与条形图相同的颜色,但由于条形图颜色较浅,因此显示效果不佳,如以下屏幕截图所示。

在此处输入图片描述

查看文档后,我发现了如何更改标签和图例的颜色,但这正是我想要的。

关于如何改变字体颜色有什么建议吗?

先谢谢了,

温贝托


这是我当前场景的一个简单演示。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{pgfplots}

\definecolor{magicmint}{rgb}{0.67, 0.94, 0.82}
\definecolor{columbiablue}{rgb}{0.61, 0.87, 1.0}
\definecolor{lavenderblue}{rgb}{0.8, 0.8, 1.0}

\pgfplotsset{compat=1.9,}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar stacked,nodes near coords,
    bar width=0.4, 
    ]
    \addplot+ [ybar, magicmint!80!black, fill=magicmint] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
    \addplot+ [ybar, columbiablue!80!black, fill=columbiablue] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
    \addplot+ [ybar, lavenderblue!80!black, fill=lavenderblue] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)}; \end{axis}
\end{tikzpicture}
\end{document}

答案1

要将文本颜色更改为黑色,请text=black按照以下示例所示使用:

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{pgfplots}

\definecolor{magicmint}{rgb}{0.67, 0.94, 0.82}
\definecolor{columbiablue}{rgb}{0.61, 0.87, 1.0}
\definecolor{lavenderblue}{rgb}{0.8, 0.8, 1.0}

\pgfplotsset{compat=1.9,}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar stacked,nodes near coords,
    bar width=0.4, 
    ]
    \addplot+ [ybar, magicmint!80!black, fill=magicmint, text=black] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
    \addplot+ [ybar, columbiablue!80!black, fill=columbiablue, text=black] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)};
    \addplot+ [ybar, lavenderblue!80!black, fill=lavenderblue, text=black] coordinates
        {(0,1) (1,1) (2,3) (3,2) (4,1.5)}; \end{axis}
\end{tikzpicture}
\end{document}

相关内容