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](https://i.stack.imgur.com/dOJC3.jpg)
The problem is caused by the combination of clip=false
and ybar stacked
: For some reason, this makes the nodes near coords
disappear (looks like a bug to me).
You can avoid this problem by placing the paper node first, outside the axis. That way, everything will automatically be drawn on top of the paper background, without any need for using layers:
![](https://i.stack.imgur.com/NdOf6.png)
\documentclass[border=5mm]{standalone}
\usepackage{tikz,pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{calc,decorations.pathmorphing}
%Use the new axis label placement features
\pgfplotsset{compat=1.8}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\pgfplotstableread[col sep=comma]{
category, mass, other
{dollars\\\$3.14m}, 31, 69
{donors\\56\,000}, 21, 79
}\warren
\newcommand{\plotsize}{width=6cm, height=5cm}
\newcommand{\boxsize}{(6,5)}
\newcommand{\boxspot}{(-2,-2)}
\newcommand{\titlepos}{(2.0,-1.5)}
\newcommand{\legendpos}{(0.17, -0.02)} %fraction of plotsize
\pgfplotsset{every axis legend/.append
style={at={\legendpos},anchor=north west,fill=none}
}
\tikzset{
pencildraw/.style={ %
decorate,
decoration={random steps,segment length=6pt,amplitude=3pt}
} %
}
\begin{tikzpicture}[font=\sffamily\sansmath]
\path[clip,pencildraw] \boxspot rectangle \boxsize;
\node{
\includegraphics[scale=1.5]{newsprint}
};
\begin{axis}[
ybar stacked,
ymin=0,
ymax=100,
bar width=35pt,
enlarge x limits={abs=20pt},
\plotsize,
hide y axis,
axis x line*=top,
axis line style={opacity=0},
xtick style={opacity=0},
xtick=data,
xticklabel style={align=center, on layer=axis foreground},
xticklabel pos=upper,
xticklabels from table={\warren}{category},
nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}\%},
nodes near coords align={anchor=east,xshift=-5.5mm,yshift=-3mm},
point meta=explicit,
]
\legend{Massachusetts, out of state};
\addplot [fill=blue] table [x expr =\coordindex, y=mass, meta=mass] {\warren};
\addplot [fill=yellow] table [x expr =\coordindex, y=other,
meta=other]{\warren};
\end{axis}
\node at \titlepos {\large Elizabeth Warren's Fundraising};
\end{tikzpicture}
\end{document}
Best Answer
Result: