[Tex/LaTex] How to set axis label background color to opaque

graphicspgfplotstikz-pgf

For a presentation, I want to overlap two images with the second one covering the first one completely.
The second one is created using pgfplots. I can set the background of the axis area to white, but not the label area.
See here:Image Overlap
How can I set the xlabel and ylabel areas to opaque as well?

\documentclass[12pt, a5paper]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage[a5paper, landscape, left=15mm, right=15mm, top=10mm, bottom=10mm]{geometry}
\usepackage{lmodern}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}
\usetikzlibrary{spy, backgrounds, positioning}
\usepackage{pgfplotstable}
\usepackage{xcolor}
\usepackage{amsmath}

\begin{document}

%% load the pictures from the web, if necessary
\IfFileExists{./infrarotPlot.pdf}
{}
{
    \write18{wget -O ./infrarotPlot.pdf http://pgfplots.net/media/tikz/examples/PDF/infrared.pdf}
}

\pagestyle{empty}

\begin{tikzpicture}[fill opacity=0.95,draw opacity=1]

\node(image1) at (0,0) {\includegraphics[width=0.8\textwidth]{infrarotPlot}};  %\raisebox{-0.5\height}

\node(image2)[anchor=north west] at (-7,-4)
{
\begin{axis}[
width=0.7\textwidth,
height=0.8\textheight,
scale only axis,
xmin=0,
xmax=1,
xlabel={Dimensionless number $\zeta$ (-)},
x axis line style={opacity=0.9},
ymin=0,
ymax=2000,
ylabel={Resulting pressure $\Sigma p$ (bar)},
y axis line style={opacity=0.9},
axis background/.style={fill=white},
legend style={at={(0.73,0.97)},anchor=north west,draw=black,fill=white,legend cell align=left}
]
%% Formula 1
\addplot[blue, domain=0:1, samples=101]
{2000*(1 - x^2)};
\addlegendentry{Formula 1};
\end{axis}
};
\end{tikzpicture}

\end{document}

The * axis line style properties do not seem to accomplish this.
Also, the positioning is quite clumpsy. I tried to use \raisebox as suggested here, but it gives an error, so does not seem to work inside tikzpicture.

—Comment on @torbjørn-t 's answer—

Thanks for the hint to the at key. However, using your first solution it gives me this, where some parts of the underlying image (some of which are highlighted by red squares) are still visible!
imageOverlap2
Isn't there a way to just define the background of the whole plot instead of each element one by one?

Best Answer

I think you're after

ylabel style={fill=white,fill opacity=0.9},
xlabel style={fill=white,fill opacity=0.9},

If you want the ticklabels as well, add a similar ticklabel style, as in the code below (commented). (There are also xticklabel style and yticklabel style if you just want to affect one axis.)

Don't put an axis inside a node, use the at (and optionally the anchor) key. As for the positioning, you need to explain what you want to do.

\documentclass[12pt, a5paper]{scrartcl}
\usepackage[a5paper, landscape, left=15mm, right=15mm, top=10mm, bottom=10mm]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}[fill opacity=0.95,draw opacity=1]

\node(image1) [inner sep=0pt] at (0,0) {\includegraphics[width=0.8\textwidth]{example-image}};  %\raisebox{-0.5\height}

\begin{axis}[
at={(image1.north east)},anchor=north east,
width=0.7\textwidth,
height=0.8\textheight,
scale only axis,
xmin=0,
xmax=1,
xlabel={Dimensionless number $\zeta$ (-)},
x axis line style={opacity=0.9},
ymin=0,
ymax=2000,
ylabel={Resulting pressure $\Sigma p$ (bar)},
ylabel style={fill=white,fill opacity=0.9},
xlabel style={fill=white,fill opacity=0.9},
%ticklabel style={fill=white,fill opacity=0.9},
y axis line style={opacity=0.9},
axis background/.style={fill=white},
legend style={at={(0.73,0.97)},anchor=north west,draw=black,fill=white,legend cell align=left},
]
%% Formula 1
\addplot[blue, domain=0:1, samples=101]
{2000*(1 - x^2)};
\addlegendentry{Formula 1};
\end{axis}
\end{tikzpicture}
\end{document}

A different route

Add image, add a white fill above, then add axis.

\documentclass[12pt, a5paper]{scrartcl}
\usepackage[a5paper, landscape, left=15mm, right=15mm, top=10mm, bottom=10mm]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}[fill opacity=0.95,draw opacity=1]
\node (image1) [inner sep=0pt] {\includegraphics[width=0.8\textwidth]{example-image}};
\fill[white,opacity=0.8] (image1.south east) rectangle (image1.north west);
\begin{axis}[
at={(image1.north east)},anchor=north east,
width=0.7\textwidth,
height=0.8\textheight,
scale only axis,
xmin=0,
xmax=1,
xlabel={Dimensionless number $\zeta$ (-)},
ymin=0,
ymax=2000,
ylabel={Resulting pressure $\Sigma p$ (bar)},
legend style={at={(0.73,0.97)},anchor=north west,draw=black,fill=white,legend cell align=left},
]
%% Formula 1
\addplot[blue, domain=0:1, samples=101]
{2000*(1 - x^2)};
\addlegendentry{Formula 1};
\end{axis}
\end{tikzpicture}
\end{document}