# Odd result in pgfplots when scale and set layers is used together

I have a problem when I use scale and set layers in pgfplots.

I have to use set layers because I want that several curves in one plot are above each other (that is not really visible in my example code below) and I want to use scale to make the plot and the labelling smaller. If you run my example code, you can see from the first figure that everything is fine if one uses set layers and scale=1. If one uses scale=0.8 without set layers, everything works as expected (second figure; in my real plot the curves are not above each other anymore). But if one uses scale=0.8 and set layers, an odd result is produced. The plot is smaller, but not the labelling. Also the legend is at wrong position.

Who can tell me what I do wrong? I really have to use set layers together with scale so that my real plot looks fine.

Here is the code I use:

\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{filecontents}{TableQuestion.txt}
xValue1 yValue1     xValue2 yValue2
1   0     1   0.2
2   1        2   0.9
3   1.5   3   1.6
4   0.5   4   0.4
\end{filecontents}
\begin{document}
\begin{tikzpicture}[scale=1]%everything ok
\begin{axis}[
set layers,
xlabel=$x$,ylabel=$y$,legend pos=north west,legend cell align=left]%
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
mark=none]%
table[x=xValue2,y=yValue2] {TableQuestion.txt};%
\legend{first entry, second entry}
\end{axis}%
\end{tikzpicture}%
\vspace{1cm}
\begin{tikzpicture}[scale=0.8]%everything ok
\begin{axis}[
%set layers,
xlabel=$x$,ylabel=$y$,legend pos=north west,legend cell align=left]%
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
mark=none]%
table[x=xValue2,y=yValue2] {TableQuestion.txt};%
\legend{first entry, second entry}
\end{axis}%
\end{tikzpicture}%
\vspace{1cm}
\begin{tikzpicture}[scale=0.8]%odd behaviour
\begin{axis}[
set layers,
xlabel=$x$,ylabel=$y$,legend pos=north west,legend cell align=left]%
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
mark=none]%
table[x=xValue2,y=yValue2] {TableQuestion.txt};%
\legend{first entry, second entry}
\end{axis}%
\end{tikzpicture}%
\end{document}

-
I have a feeling we've had a similar question before. I can't find it though. –  Seamus Jan 31 '13 at 9:49
Before I ask a question I always check if there are similar questions. Perhaps I overlooked the question you mean. I am not sure. –  partial81 Jan 31 '13 at 11:05
Well, I can't find the similar question I thought there was, so maybe I dreamed it. –  Seamus Jan 31 '13 at 11:42
Haha, perhaps you can dream of a solution too and post it ;-) –  partial81 Jan 31 '13 at 11:52

That sounds like a bug in pgfplots.

A work-around for this particular example could be to draw the tikzpicture without a scale and scale the complete tikzpicture afterwards. That could be a scalebox or tikzpicture with transform shape:

\begin{tikzpicture}[transform shape,scale=0.8]%odd behaviour
\node {%
\begin{tikzpicture}
\begin{axis}[
set layers,
xlabel=$x$,ylabel=$y$,legend pos=north west,legend cell align=left]%