This seems to be a bug in PGFPlots (update 22 January 2012: This has now been fixed): Whenever the minimum or maximum value of an axis is exactly 0, the scaling isn't applied. You can patch an internal macro to check and account for this.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,width=6cm}
%
\makeatletter
\def\pgfplots@init@scaled@tick@for#1{%
\global\def\pgfplots@glob@TMPa{0}%
\expandafter\pgfplotslistcheckempty\csname pgfplots@prepared@tick@positions@major@#1\endcsname
\ifpgfplotslistempty
% we have no tick labels. Omit the tick scale label as well!
\else
\begingroup
\ifcase\csname pgfplots@scaled@ticks@#1@choice\endcsname\relax
% CASE 0 : scaled #1 ticks=false: do nothing here.
\or
% CASE 1 : scaled #1 ticks=true:
%--------------------------------
% the \pgfplots@xmin@unscaled@as@float is set just before the data
% scale transformation is initialised.
%
% The variables are empty if there is no datascale transformation.
\expandafter\let\expandafter\pgfplots@cur@min@unscaled\csname pgfplots@#1min@unscaled@as@float\endcsname
\expandafter\let\expandafter\pgfplots@cur@max@unscaled\csname pgfplots@#1max@unscaled@as@float\endcsname
%
\ifx\pgfplots@cur@min@unscaled\pgfutil@empty
\edef\pgfplots@loc@TMPa{\csname pgfplots@#1min\endcsname}%
\expandafter\pgfmathfloatparsenumber\expandafter{\pgfplots@loc@TMPa}%
\let\pgfplots@cur@min@unscaled=\pgfmathresult
\edef\pgfplots@loc@TMPa{\csname pgfplots@#1max\endcsname}%
\expandafter\pgfmathfloatparsenumber\expandafter{\pgfplots@loc@TMPa}%
\let\pgfplots@cur@max@unscaled=\pgfmathresult
\fi
%
\expandafter\pgfmathfloat@decompose@E\pgfplots@cur@min@unscaled\relax\pgfmathfloat@a@E
\expandafter\pgfmathfloat@decompose@E\pgfplots@cur@max@unscaled\relax\pgfmathfloat@b@E
\ifnum\pgfmathfloat@a@E=0%
\pgfmathfloat@a@E=\pgfmathfloat@b@E%
\fi%
\ifnum\pgfmathfloat@b@E=0%
\pgfmathfloat@b@E=\pgfmathfloat@a@E%
\fi%
\ifnum\pgfmathfloat@b@E<\pgfmathfloat@a@E%
\pgfmathfloat@b@E=\pgfmathfloat@a@E%
\fi
\xdef\pgfplots@glob@TMPa{\pgfplots@scale@ticks@above@exponent}%
\expandafter\ifnum\pgfplots@glob@TMPa<\pgfmathfloat@b@E
% ok, scale it:
\multiply\pgfmathfloat@b@E by-1
\xdef\pgfplots@glob@TMPa{\the\pgfmathfloat@b@E}%
\else
\xdef\pgfplots@glob@TMPa{\pgfplots@scale@ticks@below@exponent}%
\expandafter\ifnum\pgfplots@glob@TMPa>\pgfmathfloat@b@E
% ok, scale it:
\multiply\pgfmathfloat@b@E by-1
\xdef\pgfplots@glob@TMPa{\the\pgfmathfloat@b@E}%
\else
% no scaling necessary:
\xdef\pgfplots@glob@TMPa{0}%
\fi
\fi
\or
% CASE 2 : scaled #1 ticks=base 10:
%--------------------------------
\c@pgf@counta=\csname pgfplots@scaled@ticks@#1@arg\endcsname\relax
%\multiply\c@pgf@counta by-1
\xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}%
\or
% CASE 3 : scaled #1 ticks=real:
%--------------------------------
\pgfmathfloatparsenumber{\csname pgfplots@scaled@ticks@#1@arg\endcsname}%
\global\let\pgfplots@glob@TMPa=\pgfmathresult
\or
% CASE 4 : scaled #1 ticks=manual:
\expandafter\global\expandafter\let\expandafter\pgfplots@glob@TMPa\csname pgfplots@scaled@ticks@#1@arg\endcsname
\fi
\endgroup
\fi
\expandafter\let\csname pgfplots@tick@scale@#1\endcsname=\pgfplots@glob@TMPa%
}
\makeatother
%
\begin{document}
\begin{tikzpicture}
\begin{axis}[ title={Scaled ticks \emph{true} with ymax \& ymin},
scaled y ticks=true,
ymax=0.0008, ymin=0
]
\addplot [cyan, domain=0:10] {0.0001*x};
\end{axis}
\end{tikzpicture}
\end{document}
The matplotlib PGF backend saves as raw PGF. What you probably want instead is pgfplots
, which you can get using tikzplotlib
, assuming your plots aren't too complex and all the features are supported.
Sample Python script for creating figure:
from pylab import *
from tikzplotlib import save as tikz_save
x = linspace(0, 10, 101)
plot(x, sin(x))
xlabel('$x$-axis')
ylabel('$y$-axis')
tikz_save('fig.tikz',
figureheight = '\\figureheight',
figurewidth = '\\figurewidth')
Sample accompanying LaTeX document that brings in the plots with two different dimensions (you could use \input
; I'm using \InputIfFileExists
so that missing figures won't kill compilation):
\documentclass{article}
\usepackage{pgfplots}
\newlength\figureheight
\newlength\figurewidth
\begin{document}
\setlength\figureheight{2in}
\setlength\figurewidth{3in}
\InputIfFileExists{fig.tikz}{}{\textbf{!! Missing graphics !!}}
\setlength\figureheight{3in}
\setlength\figurewidth{4in}
\InputIfFileExists{fig.tikz}{}{\textbf{!! Missing graphics !!}}
\end{document}
Output:
Depending on what you are doing, you could also consider using my PythonTeX package to put everything in the LaTeX source:
\documentclass{article}
\usepackage{pgfplots}
\usepackage[stdout=false]{pythontex}
% matplotlib2tikz prints messages to stdout, so don't include
% stdout automatically; could also redirect stdout to avoid this
\setpythontexworkingdir{.}
% set PythonTeX to use the document root directory as the working
% directory, so that all plots will be saved there; could use
% another location, but then would need to specify a path when
% using \input and \InputIfFileExists
\newlength\figureheight
\newlength\figurewidth
\begin{document}
\begin{pycode}
from pylab import *
from tikzplotlib import save as tikz_save
x = linspace(0, 10, 101)
plot(x, sin(x))
xlabel('$x$-axis')
ylabel('$y$-axis')
tikz_save('fig.tikz',
figureheight = '\\figureheight',
figurewidth = '\\figurewidth')
\end{pycode}
\setlength\figureheight{2in}
\setlength\figurewidth{3in}
\InputIfFileExists{fig.tikz}{}{\textbf{!! Missing graphics !!}}
\setlength\figureheight{3in}
\setlength\figurewidth{4in}
\InputIfFileExists{fig.tikz}{}{\textbf{!! Missing graphics !!}}
\end{document}
Best Answer
You could issue a direct gnuplot command as for example
set size 1,0.825
.Alternatively you can use something along the lines of
\begin{gnuplot}[terminal=epslatex, terminaloptions={size 6cm,9cm}]
.Both ways do not change the text size.
Besides that note that the cairolatex terminal avoids eps output which can be nice if you use pdflatex anyway and the tikz terminal, which is possibly the best terminal at the moment, although it slows things down and is problematic with pdflatex due to memory limitations (the memory problems are gone in luatex).