使用 tikzscale 缩放 pgfplot

使用 tikzscale 缩放 pgfplot

我使用 tikz 和 pgfplots 绘制图表。当在右侧使用第二个 y 轴时,tikz 的缩放比例不正确。因此,我尝试使用 tikzscale 包和 includegraphics,但它似乎会缩放整个图片(包括文本)。我只想缩放图表,文本大小应与文档中的大小相同。请参阅我的示例:

\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]
\addplot[red,thick] table[x index=0, y index=1]{current.txt};
\end{axis}
\end{tikzpicture}

当前.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

电压.txt

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

我的错是什么?

提前致谢

安德烈亚斯

答案1

为什么不使用该scale=<value>选项?您还可以缩放每个轴而不是整个图。请查看 pgfplots 手册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]
\addplot[red,thick] table[x index=0, y index=1]{current.txt};
\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]
\addplot[red,thick] table[x index=0, y index=1]{current.txt};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

相关内容