Same color with different patterns of a bar graph in Tikz

1,353

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}
Share:
1,353

Related videos on Youtube

M S
Author by

M S

Updated on December 20, 2020

Comments

  • M S
    M S almost 3 years

    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?

    • Budo Zindovic
      Budo Zindovic almost 7 years
    • M S
      M S almost 7 years
      I have tried but the option plot coordinates is not compatible with the postaction option @BudoZindovic
    • Budo Zindovic
      Budo Zindovic almost 7 years
      Ok then, I'll post my working solution with postaction.
  • M S
    M S almost 7 years
    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
  • Budo Zindovic
    Budo Zindovic almost 7 years
    If you can use multiple rows of entries in the legend, you can use the answer presented here.