2

When I use framed option from backgrounds tikz library for axis environment, this example works ok:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}

\begin{axis}[grid=both]
\end{axis}

\begin{axis}[xshift=2cm,yshift=3cm,width=4cm,framed]
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

but for more complicated background styles, like background rectangle/.style={draw=red,fill=white},show background rectangle nothing happend (howewer frame around subplot still appears).

If I use wrapping of axis environment into additional tikzpicture like this one:

\begin{tikzpicture}

\begin{axis}[grid=both]
\end{axis}

\begin{tikzpicture}[background rectangle/.style={draw=red,fill=white},
    show background rectangle]
  \begin{axis}[xshift=2cm,yshift=3cm,width=4cm]
  \end{axis}
\end{tikzpicture}

\end{tikzpicture}

backgound ok, but positioning fails.

How could I use backrounds with pgfplots?

Similar question: how to use backgrounds for several axis together (it's useful for different right and left axis in one plot).

3
  • For using several axes together, you don't really need the backgrounds library. There's a standard way for getting multiple axes described in the answer to Different Scales on the Same Plot
    – Jake
    Jul 3, 2011 at 6:31
  • @Jake: yes, I know. But if background applied to the one of axis, label of another one appears outside background rect. I try to apply /tikz/background/.style={} to the scope wrapping around of both axis, but nothing happened.
    – Molurd
    Jul 3, 2011 at 7:04
  • 1
    If you have nothing else in picture you could just apply the style to the whole tikzpicture environment.
    – Jake
    Jul 3, 2011 at 7:27

1 Answer 1

5

Options provided to the axis environment are in the /pgfplots key tree, but the backgrounds options have to be provided as /tikz/background/.style={}. Your example would thus look like this:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}

\begin{axis}[grid=both]
\end{axis}


\begin{axis}[
    xshift=2cm,
    yshift=3cm,
    width=4cm,
    /tikz/background rectangle/.style={
        fill=yellow,
        draw=blue
    },
    show background rectangle]
\end{axis}

\end{tikzpicture}
\end{document}

pgfplots axis with background

1
  • Thanks! It's interesting, why framed acts anyway?
    – Molurd
    Jul 3, 2011 at 6:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .