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.

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]%
\addplot[color=blue,
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
\addplot[color=red,
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]%
\addplot[color=blue,
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
\addplot[color=red,
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]%
\addplot[color=blue,
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
\addplot[color=red,
mark=none]%
table[x=xValue2,y=yValue2] {TableQuestion.txt};%
\legend{first entry, second entry}
\end{axis}%
\end{tikzpicture}%
\end{document}
share|improve this question
    
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
1  
Haha, perhaps you can dream of a solution too and post it ;-) –  partial81 Jan 31 '13 at 11:52
add comment

1 Answer

up vote 3 down vote accepted

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]%
\addplot[color=blue,
mark=*,mark layer=like plot]%
table[x=xValue1,y=yValue1] {TableQuestion.txt};%
\addplot[color=red,
mark=none]%
table[x=xValue2,y=yValue2] {TableQuestion.txt};%
\legend{first entry, second entry}
\end{axis}%
\end{tikzpicture}%
};%
\end{tikzpicture}%
share|improve this answer
    
I fear you are right and this is a bug in pgfplots – but only a little bug in a wonderful package! Your workaround works perfectly – thanks for posting it! –  partial81 Feb 4 '13 at 7:41
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.