x 軸和 y 軸的比例相同

x 軸和 y 軸的比例相同

我想在 x 軸和 y 軸上製作相同的比例,您知道這段程式碼有什麼問題嗎?

這是程式碼

\begin{tikzpicture}[>=latex]
\begin{axis}[axis x line=center,
             axis y line=center,
             xlabel style={below right},
            ylabel style={above left},
            ytick=\empty,
            xtick=\empty,
           ]
                    \addplot[name path=F,blue,domain={-2:5}] {x^3-3*x} node[pos=.8, above]{$f$};
          \addplot[name path=G,green,domain={-2:5}] {6*x}node[pos=.1, below]{$g$};
          \addplot[pattern=north west lines, pattern color=brown!50]fill between[of=F and G, soft clip={domain=-1:4}];

    \end{axis}
\end{tikzpicture}

答案1

您可能想要重新調整軟剪輯區域和節點位置,但如果您希望軸均勻縮放,您可以新增axis equal關鍵影格。

%\usetikzlibrary{intersections, pgfplots.fillbetween, patterns}
\begin{tikzpicture}[>=latex]
    \begin{axis}[axis x line=center,
                 axis y line=center,
                 xlabel style={below right},
                 ylabel style={above left},
                 ytick=\empty,
                 xtick=\empty,
                 axis equal % <---
           ]
          \addplot[name path=F,blue,domain={-2:5}] {x^3-3*x} node[pos=.8, above]{$f$};
          \addplot[name path=G,green,domain={-2:5}] {6*x}node[pos=.1, below]{$g$};
          \addplot[pattern=north west lines, pattern color=brown!50]fill between[of=F and G, soft clip={domain=-1:4}];
    \end{axis}
\end{tikzpicture}

相關內容