我正在嘗試在半對數軸內繪製一個橢圓pgfplots
。橢圓軸應與座標軸平行,但根據我選擇的半徑,橢圓會出現旋轉。
這是一個 MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\pgfplotsset{width=7cm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log]
\addplot coordinates{
(0,10) (1,300) (2,3347) (3,5000)
};
\draw
(axis cs:1,300) ellipse [
x radius = 1, y radius = 10];
\end{axis}
\end{tikzpicture}
\end{document}
產生
如何將橢圓與座標軸對齊,使它們平行於橢圓軸?
答案1
通常,我嘗試僅在 \end{axis} 之後執行正常的 tikz。相反,我保存座標以供以後使用。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\pgfplotsset{width=7cm}
\newlength{\rx}
\newlength{\ry}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log]
\addplot coordinates{
(0,10) (1,300) (2,3347) (3,5000)
};
\coordinate (Center) at (axis cs:1,300);
\coordinate (Radius) at (axis cs:2,3000);% x+1, y*10 relative to Center
\end{axis}
\pgfextractx{\rx}{\pgfpointdiff{\pgfpointanchor{Radius}{center}}{\pgfpointanchor{Center}{center}}}%
\pgfextracty{\ry}{\pgfpointdiff{\pgfpointanchor{Radius}{center}}{\pgfpointanchor{Center}{center}}}%
\draw (Center) ellipse [x radius = \rx, y radius = \ry];
\end{tikzpicture}
\end{document}