我有一张图表,我记得以前它工作得很好,突然我注意到,所有内容都缩放到了 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
自pgfplots
1.11 版本起axis cs
,这是默认坐标系。但您必须在加载包后立即1.11
至少设置。如果您没有设置 的值,则使用 。compat
pgfplots
compat
pre 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
命令。