7

Following up on the answer to proper tool for charts in tex I've built this picture to simulate/replace a scanned image from a newspaper:

enter image description here

I've tried several ways to put the background newsprint image behind the whole figure (axis labels and titles) as well as the chart, with no success.

When that's done, I'd like to have ragged edges, as in @Ipsens's answer to Torn page effect

Here's my MWE (not absolutely minimal, but small enough). The newsprint image is http://www.theblockforum.com/fun/lance/lancescollection/textures/paper2.jpg

Edit: Drawing on an image with TikZ might be helpful, but I couldn't get the example there to compile.

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{backgrounds}

%deal with warning message in log
\pgfplotsset{compat=1.8}

\newcommand{\mywidth}{10cm}
\newcommand{\myheight}{7cm}

%https://tex.stackexchange.com/questions/35872/multiline-coords
\pgfplotstableread[col sep=comma]{
name, footprint
Google search, 0.2
Movie download, 20
Daily newspaper, 170
}\carbonfootprints

\begin{document}
\begin{tikzpicture}[font=\sffamily]

\begin{pgfonlayer}{background}
   \includegraphics{newsprint}
\end{pgfonlayer}

\begin{axis}[ 
      xbar, xmin=0,
      tick style={draw=none},
      width=\mywidth, height=\myheight, 
      enlarge y limits=0.5,
      xlabel={Estimated carbon footprint, g CO${}_2$}, 
      ytick=data,
      yticklabel style={align=right},
      yticklabels={
        Google\\ search, 
        Movie\\ download,
        Daily\\ newspaper,
      },
      nodes near coords,
      nodes near coords align={horizontal}, 
    ]
    \addplot [fill=red] table [x=footprint, y expr=\coordindex] 
             {\carbonfootprints};
\end{axis} 

\end{tikzpicture}
\end{document}
8

The idea is to use the pencildraw style from Ipsenss answer to do a clipping before the axis environment; after the axis environment a \node is used to include the background image using a background layer:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{calc,decorations.pathmorphing}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

%deal with warning message in log
\pgfplotsset{compat=1.8}

\definecolor{paper}{RGB}{239,227,157}

\newcommand{\mywidth}{10cm}
\newcommand{\myheight}{7cm}

%http://tex.stackexchange.com/questions/35872/multiline-coords
\pgfplotstableread[col sep=comma]{
name, footprint
Google search, 0.2
Movie download, 20
Daily newspaper, 170
}\carbonfootprints

\tikzset{
pencildraw/.style={ %
    decorate,
    decoration={random steps,segment length=2pt,amplitude=1pt}
    } %
}

\begin{document}
\begin{tikzpicture}[font=\sffamily]
\path[clip,pencildraw] (-2.5,-40pt) rectangle (9,6);
\begin{axis}[
      xbar, xmin=0,
      tick style={draw=none},
      width=\mywidth, height=\myheight, 
      enlarge y limits=0.5,
      xlabel={Estimated carbon footprint, g CO${}_2$}, 
      ytick=data,
      yticklabel style={align=right},
      yticklabels={
        Google\\ search, 
        Movie\\ download,
        Daily\\ newspaper,
      },
      nodes near coords,
      nodes near coords align={horizontal}, 
    ]
    \addplot [fill=red] table [x=footprint, y expr=\coordindex] 
             {\carbonfootprints};
\begin{pgfonlayer}{background}
\node {\includegraphics{papiro}};
\end{pgfonlayer}
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • What I want from Ipsen's answer is the torn page effect, but with my newsprint image instead of paper color, and the background filling the whole picture, not just the plot itself. Note that in my picture the image does in fact extend a little to the right of the plot. – Ethan Bolker Jun 7 '13 at 20:48
  • @EthanBolker please see my update answer; is it something like that what you want? – Gonzalo Medina Jun 8 '13 at 0:02
  • @GonzaloMedina \includegraphics{papiro} ?? :-) – user13907 Jun 8 '13 at 0:28
  • 4
    @Papiro hehe! "Papiro" is the Spanish word for papyrus :-) – Gonzalo Medina Jun 8 '13 at 0:32

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.