Since you want to convert to an image file, the problem is one of the converter pdf -> image. TikZ as such does not fill the background (unless you do so explicitly).
If you use ImageMagick, you can use convert -transparent white
during the conversion. Other programs may require a transparency channel (perhaps you need to create one based on the color "white" as well).
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:
\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
I just want to point you to the
patterns
library of tikz. The following code and result could be a starter for you (BTW see here for similar question).It seems it is not possible to change a pattern line width. But one can look into the pgf patterns file (pgflibrarypatterns.code.tex), copy the pattern definition, and change the line width:
and change the code above to use this pattern name (my horizontal lines).