這是後續用 pgfplots 和軸方向 cs 指定圓弧半徑? 如果我想將 MWE 從那裡更改為以下內容:
\pgfplotsset{compat=1.10}
\begin{tikzpicture}
\begin{axis}[
xmin=-20,xmax=20,
]
\addplot{x}; % not important, just to make things show up
\end{axis}
\draw (axis cs:-16,0) arc[start angle=180, end angle=0, radius=8]; % <-- want to keep units of coordinate system here
\end{tikzpicture}
如何指定軸座標系中的圓弧半徑?我已經嘗試過的是給出的解決方案提取TikZ中任意點的x、y座標使用\pgfextractx
。在我的例子中,這會導致長度錯誤。
答案1
軸座標系的值在 後遺失\end{axis}
。這意味著您只能訪問命名節點(axis cs
此處甚至不可用)。
有兩種解決方案:
首先,您可以同步軸和圖片使用的單位長度,例如x=1cm, y=1cm
在軸和 中使用tikzpicture
。該軸看起來會有所不同,因為這會否決縮放策略。
或者,可以嘗試記住所要求的數量。這樣做的一種方法可能是
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-20,xmax=20,
extra description/.code={%
\pgfplotspointaxisdirectionxy{8}{8}
\pgfgetlastxy{\X}{\Y}%
\global\let\radiusX=\X
\global\let\radiusY=\Y
},
]
\addplot{x}; % not important, just to make things show up
\coordinate (P) at (axis cs:-16,0);
\end{axis}
\draw (P) arc[start angle=180, end angle=0, x radius=\radiusX, y radius=\radiusY]; % <-- want to keep units of coordinate system here
\end{tikzpicture}
\end{document}
axis direction cs
我的想法是透過巨集進行評估\pgfplotspointaxisdirectionxy
,然後得到計算出的 X 和 Y 座標並將它們記住到兩個全局巨集中。這些都是以後要用的。