1

I want to create a 2 * 2 array of XY graphs, each with a shaded region in one quadrant, and each with a label beneath. In other words, four variations on this:

enter image description here

(In case it's relevant, the code for that is

\documentclass[border=2mm]{standalone}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}

    \draw[<->] (-5.5,0) -- (5.5,0);
    \draw[<->] (0,-5.5) -- (0,5.5);
    \draw[fill=gray]  (0,5) -- (5,5) -- (5,0) -- (0,0) -- cycle;
    \node [below=5mm, align=flush center] at (0,-5)
        {
            Lorem ipsum
        };

    \end{tikzpicture}

\end{document}

)

It looked like the groupplots library was the way to go, so I did this:

\documentclass[border=2mm]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{pgfplots.groupplots} % LATEX and plain TEX

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[%
    group style={group size=2 by 2},
    height=3.5cm,
    width=3.5cm,
    /tikz/font=\small,
    axis x line=center,
    axis y line=center,
    xmin=-5.5,
    xmax=5.5,
    ymin=-5.5,
    ymax=5.5]
\nextgroupplot % parenthood
\draw[fill=gray]  (0,5) -- (5,5) -- (5,0) -- (0,0) -- cycle;
\node [below=2mm, align=flush center] at (0,-5.5)
        {
            Parenthood
        };
\nextgroupplot % mountain climbing
\draw[fill=gray]  (0,0) -- (0,5) -- (-5,-5) -- (0,-5) -- cycle;
\node [below=5mm, align=flush center] at (0,-5)
        {
            Mountain climbing
        };
\nextgroupplot % Voting
\draw[fill=gray]  (0,-1) -- (-1,5) -- (5,0) -- (0,0) -- cycle;
\node [below=5mm, align=flush center] at (0,-5)
        {
            Voting
        };
\nextgroupplot % TV
\draw[fill=gray]  (0,-5) -- (-5,-3) -- (0,-3) -- (0,0) -- cycle;
\node [below=5mm, align=flush center] at (0,-5)
        {
            Television
        };
\end{groupplot}
\end{tikzpicture}

\end{document}

Here's the result:

enter image description here

Not quite what I was going for. Those little blips in the lower left of each graph are (I think) the shaded regions I was trying to draw; the axes are labeled with min and max values (which I didn't mean to do); and the labels are completely absent. What should I change to approximate more closely the original graph?

1

pgfplots does all sorts of coordinate transformations. But there is a very simple way to shade a region: use ybar intervals. And you can also add titles to the group plots instead of adding these nodes.

enter image description here

\documentclass[border=2mm]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{pgfplots.groupplots} % LATEX and plain TEX

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[%
    group style={group size=2 by 2},
    height=3.5cm,
    width=3.5cm,
    /tikz/font=\small,
    axis x line=center,
    axis y line=center,
    xmin=-5.5,
    xmax=5.5,
    ymin=-5.5,
    ymax=5.5,
    axis on top,xticklabel=\empty,yticklabel=\empty]
\nextgroupplot[title=Parenthood] % parenthood
\addplot[ybar interval,fill=gray] coordinates {(-5,-5) (0,0)};
\nextgroupplot[title=Mountain climbing] % mountain climbing
\addplot[ybar interval,fill=gray] coordinates {(-5,-5) (0,0)};
\nextgroupplot[title=Voting] % Voting
\addplot[ybar interval,fill=gray] coordinates {(-5,-5) (0,0)};
\nextgroupplot[title=TV] % TV
\addplot[ybar interval,fill=gray] coordinates {(-5,-5) (0,0)};
\end{groupplot}
\end{tikzpicture}

\end{document}
  • How do I get rid of the numbers, so I just have the axis lines? – crmdgn Apr 20 '18 at 1:12
  • 1
    @crmdgn I made an update: xticklabel=\empty. – marmot Apr 20 '18 at 1:17

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.