これは次の続きです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
ここでは も利用できません)。
解決策は2つあります。
まず、軸と画像で使用される単位の長さを同期させることができます。たとえば、x=1cm, y=1cm
軸では を、では を使用しますtikzpicture
。これにより、スケーリング戦略が無効になるため、軸の外観が変わります。
あるいは、要求された数量を覚えておくこともできます。その方法の1つは、
\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 座標を取得して、それらを 2 つのグローバル マクロに記憶することです。これらは後で使用されます。