tikz 圖形縮放至點

tikz 圖形縮放至點

我有一個圖表,我記得它過去工作得很好,突然我注意到,所有東西都縮放到 y 軸底部的一個小點。我不確定是否有任何改變,也找不到問題。

在此輸入影像描述

\begin{tikzpicture}
    \begin{axis}[
            axis lines = middle,  %% instead of above two lines this one is enough
            scaled ticks=false,
            axis equal,
            scale=0.5,
            y=1cm,
            x=3cm,
            grid=none,
            xmax=2.5,xmin=-0.01,
            ymin=-1,ymax=5.2,
            xlabel=$x$,ylabel=$y$,
            xtick={0,0.5,1,1.5,2},
            ytick={-1,0,1,2,3,4},
            ylabel = $U(r)$,
            xlabel = $r(r_M)$,
        ]
        \draw[red, thick] (0, 5)--(0, 0)--(2.5, 0);
        \draw[domain=0.84:2.5,smooth,variable=\x,blue, thick] plot ({\x},{0.1*\x^(-12)-0.1*\x^(-6)});
    \end{axis}
\end{tikzpicture}

答案1

由於pgfplots1.11版本axis cs是預設的座標系。但你至少必須在加載包後立即1.11設定。如果您沒有設定值,請使用。compatpgfplotscompatpre 1.3

在此輸入影像描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}% comment this to see the issue
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
            axis lines = middle,  %% instead of above two lines this one is enough
            scaled ticks=false,
            axis equal,
            scale=0.5,
            y=1cm,
            x=3cm,
            grid=none,
            xmax=2.5,xmin=-0.01,
            ymin=-1,ymax=5.2,
            xlabel=$x$,ylabel=$y$,
            xtick={0,0.5,1,1.5,2},
            ytick={-1,0,1,2,3,4},
            ylabel = $U(r)$,
            xlabel = $r(r_M)$,
        ]
        \draw[red, thick] (0, 5)--(0, 0)--(2.5, 0);
        \draw[domain=0.84:2.5,smooth,variable=\x,blue, thick] plot ({\x},{0.1*\x^(-12)-0.1*\x^(-6)});
    \end{axis}
\end{tikzpicture}
\end{document}

但我會用

\plot[domain=0.84:2.5,blue, thick] {0.1*x^(-12)-0.1*x^(-6)};

而不是第二個\draw命令。

相關內容