我正在尝试在半对数轴内绘制一个椭圆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}