Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

share|improve this question
    
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 '11 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 '11 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 '11 at 7:27
add comment

1 Answer

up vote 5 down vote accepted

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

share|improve this answer
    
Thanks! It's interesting, why framed acts anyway? –  Molurd Jul 3 '11 at 6:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.