0

For my stats class, I am wanting to be able to make a pictogram (defined for this class as a bar graph with pictures for bars) similar to the ones below if required. A quick google and SE search gives nothing, so I figured I would ask. I have no idea where to start, so I cannot give any code. I do know how to use their normal versions in PGFPlots and pgf-pie, and if possible would like to stay within those packages.

Bar Chart Example

enter image description here

Pie Chart Example

enter image description here

  • 4
    Pizza with sweetcorn or pineapple? Is it for perverts? :o) – Bernard Sep 13 '17 at 19:00
  • 1
    @Bernard +1, Italians totally agree with you!!! – CarLaTeX Sep 13 '17 at 20:17
  • 1
    @Bernard -- what a waste of sweetcorn! (much better left on a cob and roasted.) – barbara beeton Sep 13 '17 at 20:30
  • @barbarabeeton: I'd rather favour slow food (‘seven hours leg of lamb’ and the like…) – Bernard Sep 13 '17 at 20:37
3

I must answer this!

For the second part, you could clip your pictures.

The "pizza" images used in the \includegraphics of my MWE are from the cook duck of the duck pond with different backgrounds, of course, you'll have to change them into your own images.

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}

\tikzset{%
    mynode/.style={draw, circle, very thick, inner sep=1.5pt},
    myseparator/.style={white, line width=1mm},
}

\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
        \begin{scope}
            \clip (0,0) -- (3,0) arc (0:75:3cm) -- cycle;
            \node{\includegraphics[width=.5\linewidth]{pizzacyan}};
        \end{scope}
        \begin{scope}
            \clip (0,0) -- ([shift={(75:3cm)}]0,0) arc (75:170:3cm) -- cycle;
            \node{\includegraphics[width=.5\linewidth]{pizzared}};
        \end{scope} 
        \begin{scope}
            \clip (0,0) -- ([shift={(170:3cm)}]0,0) arc (170:210:3cm) -- cycle;
            \node{\includegraphics[width=.5\linewidth]{pizzagreen}};
        \end{scope}
        \begin{scope}
            \clip (0,0) -- ([shift={(210:3cm)}]0,0) arc (210:360:3cm) -- cycle;
            \node{\includegraphics[width=.5\linewidth]{pizzablue}};
        \end{scope}     
        \draw[myseparator] (0,0) -- (4,0);
        \foreach \myangle in {75,170,210} {%
            \draw[myseparator] (0,0) -- ([shift={(\myangle:4cm)}]0,0);
        }       
        \foreach \myangle/\myname in
            {40/cyanslice,130/redslice,190/greenslice,290/blueslice} {%
            \node[mynode] at ([shift={(\myangle:2cm)}]0,0) (\myname) {};
        }
        \draw (cyanslice) -- ++(1.4,0) -- ++(.5,.5) node[yshift=.4cm, 
        text width=7em, anchor= north west] {{\LARGE 20\% }\\Prosciutto\\ e funghi};
        \draw (redslice) -- ++(-2,0) -- ++(-1,.5) node[yshift=.4cm, 
        text width=6em, anchor= north east, align=flush right] {{\LARGE 30\% }\\Margherita};
        \draw (greenslice) -- ++(-1.4,0) -- ++(-.5,-.5) node[yshift=.4cm, 
        text width=7em, anchor= north east, align=flush right] {{\LARGE Car\LaTeX}\\Salsiccia e \\ friarielli};
        \draw (blueslice) -- ++(2,0) -- ++(.5,-.5) node[yshift=.4cm, 
        text width=5em, anchor= north west] {{\LARGE 40\% }\\Napoletana};
        \end{tikzpicture}
        \caption*{Preferred pizzas by Italians\\ (no pineapple one on the rankings)}
    \end{figure}

\end{document}

enter image description here

P.S. = The percentages are random.

  • -1 No Hawaiian Pizza? What do the Italians know about pizza? – David Carlisle Sep 14 '17 at 7:53
  • 1
    @DavidCarlisle Italians : pizzas = DEK : TeX – CarLaTeX Sep 14 '17 at 8:06
2

As a quick hack for the first chart, you could

  • borrow the fill stretch image option from tcolorbox
  • add every bar as an individual plot

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepackage[skins]{tcolorbox}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar]
\addplot [fill stretch image=example-image-b] coordinates {(1,1)};
\addplot [fill stretch image=example-image-b] coordinates {(2,3)};
\addplot [fill stretch image=example-image-b] coordinates {(3,2)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1

Another hack for the bar plot drawn in tikz, so you need to draw the tick marks manually. The height of the bar is given in percentage. (Things can be more automated, like counting the number of bars.)

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}[>=latex]
  \newcommand\BarHeight{4}% Max height of bar picture
  \newcommand\BarWidth{1}% Width of bar picture
  \newcommand\Xdist{0.2}% Space between bars
  \newcommand\NumberBars{5}
  \draw[->] (0,0)--(0,\BarHeight cm+0.5 cm);
  \pgfmathparse{\NumberBars*(\BarWidth+\Xdist)+\Xdist+0.2}\edef\lengthxaxis{\pgfmathresult}
  \draw[->] (0,0)--(\lengthxaxis,0);
  \foreach \Num/\Label [count=\ind from 0] in {%
    80/ABC,
    60/CBS,
    40/FOX,
    100/NBC,
    70/ETC}{%
    \pgfmathparse{\Num/100*\BarHeight}\edef\Heightofbar{\pgfmathresult}
    \node[inner sep=0pt,anchor=south west,label=-90:\small\textsf{\Label}] at 
    (\ind*\BarWidth+\ind*\Xdist+\Xdist,0){%
      \includegraphics[width=\BarWidth cm, height=\Heightofbar cm]{example-image}};
  }
\end{tikzpicture}
\end{document}

enter image description here

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.