缩放整个图

缩放整个图

有一个带有 x 轴和 y 轴的绘图图,我想对其进行缩放(例如拉伸)。

我怎么做?

\begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xlabel = $x$]
%Below the red parabola is defined

%Here the blue parabloa is defined
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(x))};
\label{$sin((x))$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(2*x))};
\addlegendentry{$cos(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(2*x))};
\addlegendentry{$sin(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(x))};
\addlegendentry{$cos(x)$}

\end{axis}
\end{tikzpicture}

答案1

拉伸 pgf 图的正确方法是增加其宽度。(此外,正如 Torbjørn T. 告诉您的那样,最好编写\sin排版正弦函数。)

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16} %<- you may want to add this

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xlabel = $x$]
%Below the red parabola is defined

%Here the blue parabloa is defined
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(x))};
\label{$sin((x))$} %<- dangerous practice
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(2*x))};
\addlegendentry{$\cos(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(2*x))};
\addlegendentry{$\sin(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(x))};
\addlegendentry{$\cos(x)$}

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[width=0.9\textwidth,% <- added
    height=5cm,% <- added
    axis lines = left,
    xlabel = $x$]
%Below the red parabola is defined

%Here the blue parabloa is defined
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(x))};
\label{sin-2} %<- less dangerous 
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(2*x))};
\addlegendentry{$\cos(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {sin(deg(2*x))};
\addlegendentry{$\sin(2x)$}
\addplot [
    domain=0:9.5, 
    samples=700, 
    color=blue,
    ]
    {cos(deg(x))};
\addlegendentry{$\cos(x)$}

\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

如您所见,第二张图被“拉伸”了,因为宽度增加了而高度减少了。

相关内容