下面的代码最好地重现了该问题。
\documentclass[multi=true, crop=true]{standalone}
\usepackage{pgfplots, textcomp}
\standaloneenv{tikzpicture}
\usetikzlibrary{patterns, arrows.meta, decorations.pathreplacing, calc, matrix, positioning, angles, quotes, babel, intersections}
\pgfplotsset{compat=newest, samples=5000,
axis lines=center, axis equal,
xlabel={$x$}, ylabel={$y$},
enlarge x limits=false, enlarge x limits=false}
\begin{documment}
\begin{tikzpicture}[scale=0.75]%183
\xdef\ux{2}
\xdef\uy{1}
\xdef\vx{1}
\xdef\vy{2}
\pgfmathparse{\vy+\uy}
\xdef\sy{\pgfmathresult}
\pgfmathparse{\vx+\ux}
\xdef\sx{\pgfmathresult}
\begin{axis}[xtick=\empty, ytick=\empty, xmin=0,xmax=4, ymin=0, ymax=4,
extra y ticks={\uy, \vy, \sy}, extra y tick labels={$y_1$, $y_2$, $y_1+y_2$},
extra x ticks={\vx, \ux, \sx}, extra x tick labels={$x_2$, $x_1$, $x_1+x_2$}]
\addplot[-latex] coordinates {(0,0)(\ux,\uy)} node[midway,below]{$\overrightarrow{u}$};
\addplot[-latex] coordinates {(0,0)(\vx,\vy)} node[midway,above]{$\overrightarrow{v}$};
\addplot[dashed] coordinates {(0,\vy)(\vx,\vy)(\vx,0)};
\addplot[dashed] coordinates {(0,\uy)(\ux,\uy)(\ux,0)};
\addplot[-latex] coordinates {(0,0)({\ux+\vx},{\uy+\vy})} node[pos=0.7,above left]{$\overrightarrow{u}+\overrightarrow{v}$};
\addplot[dashed] coordinates {(\ux,\uy)({\ux+\vx},{\uy+\vy})};
\addplot[dashed] coordinates {(\vx,\vy)({\ux+\vx},{\uy+\vy})};
\addplot[dashed] coordinates {(0,{\uy+\vy})({\ux+\vx},{\uy+\vy})({\ux+\vx},0)};
\end{axis}
\end{tikzpicture}
\end{documment}
x 轴应该从 0 开始,但却从其他东西开始。我也尝试在环境axis lines=center
中设置axis
,但没有效果。在另一个图中,固定长度是 y 轴,我不知道为什么。有些图(我相信大约 10 个)有同样的问题。
答案1
解决方案 1
您只需设置 即可xmin=0.8
。还可以将\begin{documment}
和替换\end{documment}
为\begin{document}
和\end{document}
。
输入
\documentclass[multi=true, crop=true]{standalone}
\usepackage{pgfplots, textcomp}
\standaloneenv{tikzpicture}
\usetikzlibrary{patterns, arrows.meta, decorations.pathreplacing, calc, matrix, positioning, angles, quotes, babel, intersections}
\pgfplotsset{compat=newest, samples=5000,
axis lines=center, axis equal,
xlabel={$x$}, ylabel={$y$},
enlarge x limits=false, enlarge x limits=false}
\begin{document}
\begin{tikzpicture}[scale=0.75]%183
\xdef\ux{2}
\xdef\uy{1}
\xdef\vx{1}
\xdef\vy{2}
\pgfmathparse{\vy+\uy}
\xdef\sy{\pgfmathresult}
\pgfmathparse{\vx+\ux}
\xdef\sx{\pgfmathresult}
\begin{axis}[xtick=\empty, ytick=\empty, xmin=0.8,xmax=4, ymin=0, ymax=4,
extra y ticks={\uy, \vy, \sy}, extra y tick labels={$y_1$, $y_2$, $y_1+y_2$},
extra x ticks={\vx, \ux, \sx}, extra x tick labels={$x_2$, $x_1$, $x_1+x_2$}]
\addplot[-latex] coordinates {(0,0)(\ux,\uy)} node[midway,below]{$\overrightarrow{u}$};
\addplot[-latex] coordinates {(0,0)(\vx,\vy)} node[midway,above]{$\overrightarrow{v}$};
\addplot[dashed] coordinates {(0,\vy)(\vx,\vy)(\vx,0)};
\addplot[dashed] coordinates {(0,\uy)(\ux,\uy)(\ux,0)};
\addplot[-latex] coordinates {(0,0)({\ux+\vx},{\uy+\vy})} node[pos=0.7,above left]{$\overrightarrow{u}+\overrightarrow{v}$};
\addplot[dashed] coordinates {(\ux,\uy)({\ux+\vx},{\uy+\vy})};
\addplot[dashed] coordinates {(\vx,\vy)({\ux+\vx},{\uy+\vy})};
\addplot[dashed] coordinates {(0,{\uy+\vy})({\ux+\vx},{\uy+\vy})({\ux+\vx},0)};
\end{axis}
\end{tikzpicture}
\end{document}
输出
解决方案 2:
这里真正的问题是由于您要求轴相等。因此您也可以直接删除axis equal,
而不是更改 的值xmin
。