How to combine fill and pattern in a pgfplot bar plot?
You can use a postaction
to draw the pattern after the yellow background.
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar, samples=10, enlarge y limits=upper, ymin=0]
\addplot +[
black,
fill=yellow,
postaction={
pattern=north east lines
}
]{rnd};
\end{axis}
\end{tikzpicture}
\end{document}
In older versions of PGFfplots, you needed to use every path
to apply the pattern.
In order to apply the postaction, you can use every path/.style={postaction={...}}
. This requires that you clear the postaction, e.g. using the approach given in Applying a postaction to every path in TikZ, as otherwise you get an infinite recursion.
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\makeatletter
\tikzset{nomorepostaction/.code=\let\tikz@postactions\pgfutil@empty}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar, samples=10]
\addplot +[
black,
fill=yellow,
every path/.style={
postaction={
nomorepostaction,
pattern=north east lines
}
}
]{rnd};
\end{axis}
\end{tikzpicture}
\end{document}
I think the answer is yes: by two separate path instructions with the same path: one without pattern but with fill color and one with the chosen pattern.
In terms of the \addplot
command of pgfplots: two separate \addplot
commands, one with \addplot[fill,forget plot,...]
and one with the pattern. The forget plot
tells pgfplots to avoid legend entries for the plot.
If this appears to be unsuitable, you may want to look into decorations - perhaps they support such a thing.