Re: [Pgfplots-features] Plotting ellipse in the axis coordinate system
Brought to you by:
cfeuersaenger,
ludewich
From: Stefan P. <Mo...@gm...> - 2010-04-02 19:34:17
|
Hello Frank, hello Christian, I recently had the same problem and Christians solution seems to work fine, as long as you don't have to rotate the ellipsis. In this case you get some strange results. Change the \Xmax/\Ymax or width/height values in my given "minimal" to see what I am talking about. I used a workaround where I just set a node in the axis and then draw the ellipsis on that point after the axis ended. My issue was to "fit" the data points into the ellipsis which didn't work with the fit library, so I it with trial and error. Of course for that Christians solution also works, but if somebody needs a correct rotated ellipsis his solution has to be improved. Best regards Stefan Pinnow \documentclass{article} \usepackage{pgfplots} % A helper command because I don't want to fool around with \pgfextractx % and \pgfextray: \makeatletter % it defines "#1' to contain the x coord value and #2 to contain the y % coord value \newcommand{\extractpgfxy}[2]{% \edef#1{\the\pgf@x}% \edef#2{\the\pgf@y}% }% \makeatother \begin{document} \begin{tikzpicture} \def\Xmax{3} \def\Ymax{3} \def\X{1} \def\Y{2} \begin{axis}[ width=8cm, height=8cm, scale only axis=true, % xmin=-\Xmax, xmax=\Xmax, ymin=-\Ymax, ymax=\Ymax, % extra x ticks={-\X,\X}, extra y ticks={-\Y,\Y}, extra tick style={grid=major}, ] % Trying to plot an ellipse centered at coordinates (2,-1) and having % half axes of legnth 1 and 2. \pgfplotsextra{% <--- important! % % we compute the (x,y) coordinates as difference to be % independent of the (0pt,0pt) used internally by pgfplots \pgfpointdiff {\pgfplotspointaxisxy{0}{0}} {\pgfplotspointaxisxy{\X}{\Y}} \extractpgfxy{\RADIUSX}{\RADIUSY}% % % I used the option form for ellipse because the '\RADIUSX and' seems % to be a problem in pgf (?) \draw[black] (axis cs:0,0) ellipse [ x radius=\RADIUSX,y radius=\RADIUSY]; \draw[red] (axis cs:0,0) ellipse [rotate=90,x radius=\RADIUSX,y radius=\RADIUSY]; } \addplot [only marks,mark=*] coordinates { (0,0) }; \end{axis} \end{tikzpicture} \end{document} |