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.

Applying a scale option to a TikZ picture works great. It keeps the text the proper size and scales everything else. I would like to have the same behavior when using a \begin{axis}...\end{axis}.

Consider the following in which the first graphic does not use the {axis} environment. Changing the scale works great. However, try changing the scale option of the second \begin{tikzpicture} to scale=1.5. This has the effect that the x and y axis labels are moved far away form the axis.

Furthermore, I can see no apparent change in the scale option applied to \begin{axis}. I don't see any error messages complaining about it, so it must be a valid option.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[scale=1.0]
\draw [->][gray, thin](-3,0) -- (3,0)
    node[blue, right] {$x$}; 

\draw [->][gray, thin] (0,-3) -- (0,3)
    node[blue, above] {$y$};
\end{tikzpicture}

\begin{tikzpicture}[scale=1.0]
\begin{axis}[scale=1.5 % Has no effect
    minor tick num=0, 
    axis y line=center, 
    axis x line=middle, 
    xmin=-3,
    xmax=3, 
    ymin=-3,
    ymax=3,
    xlabel=$x$,
    ylabel=$y$
    ]
\end{axis}
\end{tikzpicture}
\end{document}

Also, one other minor nit-pick now that I posted this: How do I got about getting the x,y labels within {axis} to be to the right and on top as in the first example?

share|improve this question
1  
Seeing you posted a new question saying you didn't get a good answer to this one: Maybe you could clarify what it is exactly you're trying to achieve here? If the question is "How do I make a PGFplots larger without changing line widths and font sizes?", then the answer is given below: Use widthand height (or the development version's scale option). If the question is "How do I scale a tikzpicture which, among other things, contains a PGFplots axis, while keeping line widths and font sizes", then the answer is: You can't; the axis environment is jus too complex for this. –  Jake May 20 '11 at 10:03
1  
@Jake: Sorry, I did not mean to imply that the postings here not good. They are extremely helpful, I just have to wait until these changes make it to the released versions. The other question has similar behavior but without the scale adjustment - I referenced this question in case the problem is related. –  Peter Grill May 20 '11 at 16:50

1 Answer 1

up vote 11 down vote accepted

In order to adjust the size of a plot without changing the text size, you should use the width and height options. There is no scale option for this, unfortunately: You'll have to multiply the width and height yourself.

The development version contains the options x post scale and y post scale (which are marked EXPERIMENTAL in the source code, but seem to work fine). This will in effect increase the width and height of the plot, so it's not really just scaled: Depending on whether you increase or decrease the size of the plot, you will get more or less tick lines. This is a sensible thing, I believe, but maybe not what you need?

To install the development version using TeXLive, you can use the command sudo -i tlmgr update pgfplots --repository http://tlcontrib.metatex.org/2010

You can then define a new scale style that sets all post scale options to the same value simultaneously:

\pgfkeys{/pgfplots/scale/.style={
  x post scale=#1,
  y post scale=#1,
  z post scale=#1}
}

In order to place the x label and y label at the ends of the axes, you can use the following options:

xlabel style={at={(current axis.right of origin)}, xshift=1.5ex, anchor=center},
ylabel style={at={(current axis.above origin)}, yshift=1.5ex, anchor=center}

Here's a complete example:

\documentclass{minimal}
\usepackage{pgfplots}

\begin{document}
\pgfkeys{/pgfplots/scale/.style={
  x post scale=#1,
  y post scale=#1,
  z post scale=#1}
}

\pgfkeys{/pgfplots/axis labels at tip/.style={
    xlabel style={at={(current axis.right of origin)}, xshift=1.5ex, anchor=center},
    ylabel style={at={(current axis.above origin)}, yshift=1.5ex, anchor=center}}
}

\begin{tikzpicture}
\begin{axis}[
    axis y line=center, axis x line=middle, xmin=-3, xmax=3, ymin=-3, ymax=3, xlabel=$x$,ylabel=$y$,
    axis labels at tip
    ]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
    scale=0.6,
    axis y line=center, axis x line=middle, xmin=-3, xmax=3, ymin=-3, ymax=3, xlabel=$x$,ylabel=$y$,
    axis labels at tip
    ]
\end{axis}
\end{tikzpicture}
\end{document}

scaled pgfplots plot

share|improve this answer
    
I am getting an Package pgfkeys Error: I do not know the key '/tikz/x post scale' and I am going to ignore it. Perhaps you misspelled it.. I had done a complete update about 3 weeks ago so should have the latest. The log file lists pgfplots 2010/07/14 Version 1.4.1. Is there a later version? –  Peter Grill May 5 '11 at 17:17
    
@Peter: Oh yes, sorry, it's only been added to the development version. I'll change the answer to reflect this. –  Jake May 6 '11 at 8:11
    
thanks for the investigation with that style. I'll include it in pgfplots for the moment as this appears to be a bug. –  Christian Feuersänger May 9 '11 at 19:33
3  
This now seems to be working as advertised with TeXLive2011. –  Peter Grill Nov 3 '11 at 22:48

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.