轴上的刻度相同,但轴的长度不同

轴上的刻度相同,但轴的长度不同

我有一个分段函数图。定义域从 到-22范围从-88。我指定width=2.5inheight=2.5inaxis equal。这些指定不应该给我沿轴的相同缩放比例吗?(“如果x图上向右移动每厘米对应于 的变化1,则图上向上移动每x厘米对应于 的变化1。”)为什么x- 轴是从 到 绘制-88

\documentclass[10pt]{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\begin{tikzpicture}
\begin{axis}[width=2.5in, height=2.5in, axis equal, axis on top, clip=false,
    axis lines=middle,
    xmin=-2,xmax=2, domain=-2:2,
    ymin=-8,ymax=8,
    restrict y to domain=-8:8,
    xtick={\empty},ytick={\empty},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel=\textit{x},ylabel=\textit{y},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=7.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=7.5pt, anchor=south west}
]

\addplot[samples=501, domain=-2:0] {-x^3};
\addplot[samples=2, domain=0:1] {x + 1};
\addplot[samples=2, domain=1:2] {-7} node[anchor=west, pos=1, font=\scriptsize]{\makebox[0pt][l]{$y=f(x)$}};

\coordinate (P) at (0,0);
\coordinate (Q) at (0,1);
\coordinate (R) at (1,-7);

\end{axis}

\draw[fill=white] (P) circle (1.5pt);
\draw[fill] (Q) circle (1.5pt);
\draw[fill=white] (R) circle (1.5pt);

\end{tikzpicture}

\end{document}

答案1

确实,axis equal保证两个轴的缩放比例相同,但它也常常会产生不理想的效果,即扩大它们的限制(第 4.10 节pgfplots 文档)。

如果您想x-22,那么这axis equal image就是要走的路。此选项将使单位相同,但将变量保持在您指定的值内。

代码如下:

\documentclass[10pt]{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        width=2.5in,
        axis equal image, 
        axis on top, 
        clip=false,
        axis lines=middle,
        xmin=-2,
        xmax=2, 
        domain=-2:2,
        ymin=-8,
        ymax=8,
        restrict y to domain=-8:8,
        xtick={\empty},
        ytick={\empty},
        axis line style={latex-latex},
        xlabel=\textit{x},
        ylabel=\textit{y},
        axis line style={
            shorten >=-7.5pt, 
            shorten <=-7.5pt
        },
        xlabel style={
            at={(ticklabel* cs:1)}, 
            xshift=7.5pt, 
            anchor=north west
        },
        ylabel style={
            at={(ticklabel* cs:1)},
            yshift=7.5pt, 
            anchor=south west
        }
    ]

        \addplot[samples=501, domain=-2:0] {-x^3};
        \addplot[samples=2, domain=0:1] {x + 1};
        \addplot[samples=2, domain=1:2] {-7} node[anchor=west, pos=1, font=\scriptsize]{\makebox[0pt][l]{$y=f(x)$}};

        \coordinate (P) at (0,0);
        \coordinate (Q) at (0,1);
        \coordinate (R) at (1,-7);

    \end{axis}

    \draw[fill=white] (P) circle (1.5pt);
    \draw[fill] (Q) circle (1.5pt);
    \draw[fill=white] (R) circle (1.5pt);

\end{tikzpicture}

\end{document}

以下是最终的剧情:

在此处输入图片描述

请注意,我们可以去掉 或heightwidth规范。一旦我们设置了 (例如,英寸height),width就会立即受到限制,因此x会从-22以与垂直轴相同的步长变化。

相关内容