![贝塞尔曲线中 pgfplots 相对负坐标的问题](https://linux22.com/image/398233/%E8%B4%9D%E5%A1%9E%E5%B0%94%E6%9B%B2%E7%BA%BF%E4%B8%AD%20pgfplots%20%E7%9B%B8%E5%AF%B9%E8%B4%9F%E5%9D%90%E6%A0%87%E7%9A%84%E9%97%AE%E9%A2%98.png)
我尝试在图形中绘制一些贝塞尔曲线pgfplots
。当坐标为正时,这种方法效果很好。参见:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ axis x line=middle, axis y line=middle,
xmin = 0, xmax = 11, ymin = 0, ymax=4,
unit vector ratio=1 1, grid,
xlabel = $x$, ylabel = $y$]
\draw[blue, thick] (axis cs:1,1.5)
.. controls (axis cs:1.2,2.5) and +(axis cs:-0.5,0) ..
(axis cs:2,3.5)coordinate(A)
.. controls +(axis cs:0.5,0) and +(axis cs:-6,0) ..
(axis cs:11,1.55);
\draw[red,<->] (A) +(axis cs:-0.8,0) --+(axis cs:0.8,0);
\end{axis}
\end{tikzpicture}
问题是,当我对负 x 坐标尝试执行相同的操作时(尽管使用了axis direction cs
语法):
\begin{tikzpicture}
\begin{axis}[axis x line=middle, axis y line=middle,
xmin = -11, xmax = 0, ymin = 0, ymax=4,
unit vector ratio=1 1, grid,
xlabel = $x$, ylabel = $y$]
\draw[blue, thick] (axis cs:-1,1.5)
.. controls (axis direction cs:-1.2,2.5) and +(axis direction cs:0.5,0) ..
(axis cs:-2,3.5)coordinate(B)
.. controls +(axis direction cs:-0.5,0) and +(axis direction cs:6,0) ..
(axis cs:-11,1.55);
\draw[red,<->] (B) +(axis direction cs:-0.8,0) --+(axis direction cs:0.8,0);
\end{axis}
\end{tikzpicture}
任何帮助都将不胜感激。谢谢。
答案1
解决方案很简单:正如@marmot 在评论中指出的那样,有一个错误:我使用的axis direction cs
是非相对坐标定义。应用此修正后,代码按预期运行:
\begin{tikzpicture}
\begin{axis}[axis x line=middle, axis y line=middle,
xmin = -11, xmax = 0, ymin = 0, ymax=4,
unit vector ratio=1 1, grid,
xlabel = $x$, ylabel = $y$]
\draw[blue, thick] (axis cs:-1,1.5)
.. controls (axis cs:-1.2,2.5) and +(axis direction cs:0.5,0) .. % replacement
(axis cs:-2,3.5)coordinate(B)
.. controls +(axis direction cs:-0.5,0) and +(axis direction cs:6,0) ..
(axis cs:-11,1.55);
\draw[red,<->] (B) +(axis direction cs:-0.8,0) --+(axis direction cs:0.8,0);
\end{axis}
\end{tikzpicture}