Tikz 中条形图的相同颜色和不同图案

Tikz 中条形图的相同颜色和不同图案

如何绘制一个条形图,使所有条形具有相同的填充颜色但具有不同的图案?

我试过了,但还不完整。任何帮助我都感激不尽。

MWE如下:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepgfplotslibrary{groupplots}


\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
legend columns=-1,
legend entries={{\color{red}{\tiny Random}},{\color{blue}{\tiny ++Cost}},{\color{black}{\tiny ++FTE}},{\color{green}{\tiny ++Resources}},{\color{orange}{\tiny Hold All}}},
legend to name=CombinedLegendBar,
area legend, 
group style={
group size=1 by 1,
xlabels at=edge bottom,
ylabels at=edge left,
xticklabels at=edge bottom}]
\nextgroupplot[bar width=17pt, xticklabels=\empty]
\addplot[ybar, pattern=horizontal lines] coordinates {  (1, 12)};
\addplot[ybar, pattern=vertical lines] coordinates { (2, 3)};
\addplot[ybar, pattern=grid] coordinates {  (3, 3)};
\addplot[ybar, pattern=dots] coordinates {  (4, 2)};
\addplot[ybar, pattern=north east lines] coordinates {  (5, 2)};


\end{groupplot}
\end{tikzpicture}
\ref{CombinedLegendBar}
\caption{Triage++ Performance}
\label{PlusPlusCombinedBar}
\end{figure}
\end{document}

我需要填充条形颜色以及不同的图案。我还希望图例以单一颜色显示。有什么方法吗?

答案1

您也可以为每个条形图使用不同的颜色(我yellow为所有条形图使用了不同的颜色)。我提供了您可以根据需要自定义的通用 MWE:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepgfplotslibrary{groupplots}


\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
legend columns=-1,
legend entries={{\color{red}{\tiny Random}},{\color{blue}{\tiny ++Cost}},{\color{black}{\tiny ++FTE}},{\color{green}{\tiny ++Resources}},{\color{orange}{\tiny Hold All}}},
legend to name=CombinedLegendBar,
area legend, 
group style={
group size=1 by 1,
xlabels at=edge bottom,
ylabels at=edge left,
xticklabels at=edge bottom}]
\nextgroupplot[bar width=17pt, xticklabels=\empty]
\addplot[ybar, fill=yellow,  postaction={
        pattern=horizontal lines
    }] coordinates {  (1, 12)};
\addplot[ybar, fill=yellow,  postaction={
         pattern=vertical lines}] coordinates { (2, 3)};
\addplot[ybar, fill=yellow,  postaction={
        pattern=grid}] coordinates {  (3, 3)};
\addplot[ybar, fill=yellow,  postaction={
        pattern=dots}] coordinates {  (4, 2)};
\addplot[ybar, fill=yellow,  postaction={
        pattern=north east lines}] coordinates {  (5, 2)};


\end{groupplot}
\end{tikzpicture}
\ref{CombinedLegendBar}
\caption{Triage++ Performance}
\label{PlusPlusCombinedBar}
\end{figure}
\end{document}

相关内容