0

I have a bar plot graph and I want to use patterns to fill the columns. However it seems that patterns are not working. For compiling I use pdflatex or lualatex.

I also wanted to use pattern width different fill color. Is that possible?

\documentclass[10pt,border=0pt]{standalone}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{pgfplots}

\usetikzlibrary{patterns}

\pgfplotsset{every tick/.style={black,}}

\pgfplotsset{%
    compat=1.8,
    compat/show suggested version=false,
    ybar,
    tick label style={font=\footnotesize},
    label style={font=\footnotesize},
    legend style={%
        font=\footnotesize,
        at={(0.5,-0.15)},
        anchor=north,
        legend columns=2
        legend cell align=left,
        nodes={inner xsep=2pt,inner ysep=0.4pt,text depth=0.15em},
    },
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%
    ylabel={y-axis},
    symbolic x coords={AAA,BBB},
    xtick=data,
    bar width=16pt,
    enlarge x limits=0.4,
    nodes near coords,
    font=\footnotesize,
    legend entries={C,D,E,G},
]

    \addplot[pattern=horizontal lines] coordinates {(AAA,0.32) (BBB,0.43)};
    \addplot[pattern=vertical lines] coordinates {(AAA,0.91) (BBB,0.93)};
    \addplot[pattern=north east lines] coordinates {(AAA,0.19) (BBB,0.16)};
    \addplot[pattern=north west lines] coordinates {(AAA,0.74) (BBB,0.72)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2

For the pattern color use:

\addplot[red,pattern=horizontal lines, pattern color=red] coordinates {(AAA,0.32) (BBB,0.43)};

The first red is for the contour of the bar e the pattern color=red is for the pattern itself.

What errors do you have? I use pgfplots 1.5.1 so I use compat=1.5 and I comment your compat/show suggested version=false line and this works for me.

enter image description here

  • 1
    It seems in the newer versions of PGFplots it only works when compiling with latex+dvips+ps2pdf or latex+dvipdf. – cacamailg May 31 '13 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.