# Scaling pgfplot with tikzscale

I'm using tikz and pgfplots for graphs. When using a second y-axis on the right the scaling of tikz is not proper. So I tried to use the tikzscale package and the includegraphics but it seems to scale the whole picture including text. I want to scale only the diagram, text size should be the same as in the document. See my example:

\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{pgfplots}
\begin{document}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text     text text text text text text text text text text text text.
\begin{figure}
\includegraphics[width=\textwidth]{tikzpicture.tikz}
\end{figure}
\end{document}


tikzpicture.tikz:

\begin{tikzpicture}

\begin{axis}[width=\textwidth,height=0.3\textheight,
axis  y  line*=left,
grid,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1200,
ytick={0,200,400,600,800, 1000,1200},
xlabel=time,
ylabel=Volt]
\addplot[blue] table[x index=0, y index=1] {voltage.txt};
\end{axis}
\begin{axis}[width=\textwidth,height=0.3\textheight,
axis  y  line*=right,
axis  x  line=none,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1500,
ytick={0,250,500,750,1000,1250,1500},
ylabel=Ampere]
\end{axis}
\end{tikzpicture}


current.txt:

-29.068 0.69475
10.932  48.518
50.932  280.56
90.932  350.94
130.93  329.44
1010.9  -2.9516


voltage.txt

-40.268 998.72
-0.268  975.43
39.732  880.89
199.73  662
239.73  595.4
999.73  -26.092


Whats my fault?

Andreas

Why don't you use the scale=<value> option? You can also scale every single axis instead of the whole plot. check the pgfplots manual for post scale={scale}.

\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{current.txt}
-29.068 0.69475
10.932  48.518
50.932  280.56
90.932  350.94
130.93  329.44
1010.9  -2.9516
\end{filecontents}
\begin{filecontents}{voltage.txt}
-40.268 998.72
-0.268  975.43
39.732  880.89
199.73  662
239.73  595.4
999.73  -26.092
\end{filecontents}

\begin{document}
text
\begin{figure}
\begin{tikzpicture}
%
\pgfplotsset{set layers}
%
\begin{axis}[width=\textwidth,height=0.3\textheight,
axis  y  line*=left,
grid,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1200,
ytick={0,200,400,600,800, 1000,1200},
xlabel=time,
ylabel=Volt]
\addplot[blue] table[x index=0, y index=1] {voltage.txt};
\end{axis}
\begin{axis}[width=\textwidth,height=0.3\textheight,
axis  y  line*=right,
axis  x  line=none,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1500,
ytick={0,250,500,750,1000,1250,1500},
ylabel=Ampere]
\end{axis}
\end{tikzpicture}
\end{figure}
%
\begin{figure}
\begin{tikzpicture}
%
\pgfplotsset{set layers}
%
\begin{axis}[width=\textwidth,height=0.3\textheight,
scale=0.5,  %<-- scale option
axis  y  line*=left,
grid,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1200,
ytick={0,200,400,600,800, 1000,1200},
xlabel=time,
ylabel=Volt]
\addplot[blue] table[x index=0, y index=1] {voltage.txt};
\end{axis}
\begin{axis}[width=\textwidth,height=0.3\textheight,
scale=0.5,   %<-- scale option
axis  y  line*=right,
axis  x  line=none,
xlabel near ticks,
ylabel near ticks,
xmin=-50,
xmax=1000,
ymin=-50,
ymax=1500,
ytick={0,250,500,750,1000,1250,1500},
ylabel=Ampere]

• Sorry, but I do not understand clearly what you want?!?! scaling as in the MWE in my answer leaves the text size constant. I don't have to use the tikzscale-package and right and left y-axis are looking good. Why do you wanna scale to textwidth while using the width=\textwidth option? Do be very sure that the width of the plot is textwidth. you can specify width=\textwidth-90pt. Because 45pt is the space reserved for the labels and you have one at each y axis. Maybe it would help to provide a MWE without the tikzscale package so that one can see properly what doesn't work!?!?! – prankenandi Aug 11 '14 at 9:05
• I would recommend to read in the manual the section scaling options. – prankenandi Aug 11 '14 at 10:38
• the manual says width={dimension} -Sets the width of the final picture to {dimension}. And 45pt is a fixed amount. takes the description more space then 45pt the final picture will be larger then textwidth. but with the fixed amount the axis box has always the same size! You could also use scale only axis and scale only the axis box to0.8\textwidth. this way you don't have to worry about the labels.But as I said maybe check the manual to get a better idea about scaling options.cheers – prankenandi Aug 11 '14 at 10:52