0

How to draw a bar graph with all the bar having a same filled color along with different patterns?

I have tried but it is incomplete. Any help is appreciated.

The MWE is as follows:

\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}

I need to fill the bar color, along with the different patterns. I also want the legend to be displayed in a single color. Does there exist any way?

M S
  • 1,552

1 Answers1

1

You can use different colours for every bar as well (I used yellow for all bars). I provided the general MWE that you can customize to your need:

\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}
  • Thank You!!! One more query.. Suppose if I am having long text as legend. How to represent this to fit in a two column document?? @ Budo Zindovic – M S Dec 19 '16 at 15:28
  • 1
    If you can use multiple rows of entries in the legend, you can use the answer presented here. – Budo Zindovic Dec 22 '16 at 14:11