1

This is a follow up on Specify radius of an arc with pgfplots and axis direction cs? If I'd like to change the MWE from there to the following:

\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}

How can I specify the arc radius in axis coordinate system? What I already tried was a solution given in Extract x, y coordinate of an arbitrary point in TikZ using \pgfextractx. This leads to wrong lengths in my case.

goeck
  • 216
  • You need that inside axis environment. The axis cs: part is not needed since pgfplots 1.11 IIRC. – Manuel Dec 19 '14 at 11:09
  • You're right @Manuel. The thing is, I need to do that outside, because I have some automatically named nodes (comding from pgfplots axis environment) that are available just after the axis environment has ended. I draw some arcs based upon those points. See the already solved question regarding this drawing order http://tex.stackexchange.com/questions/196641/tikz-nodes-in-pgfplots-saved-for-later-use-but-locations-mismatch – goeck Dec 19 '14 at 11:50
  • This is a little too easy for the MWE compared to your comment. Can you include your real case a little more realistic if possible? – percusse Dec 19 '14 at 16:29
  • I think though this hint is not wrong, in this case the MWE is sufficient to comply my needs. I use this in a way more complicated use case but just looking at the core of the issue, this MWE is good from my point of view. I don't want you guys having to digg deep down into my use case but rather showing a more universally approach. Hope this goes fine with most you, otherwise I have to construct another MWE. Please give me a short feedback then. – goeck Dec 21 '14 at 12:44

1 Answers1

4

The values of the axis coordinate system are lost after \end{axis}. That means you can only access named nodes (not even axis cs is available here).

There are two solutions:

First, you can synchronize the unit lengths used by the axis and your picture, for example using x=1cm, y=1cm in the axis and in the tikzpicture. The axis will look differently since this overrules the scaling strategies.

Alternatively, one could try to remember the requested quantity. A way to do so might be

\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}

enter image description here

My idea is to evaluate axis direction cs by means of the macro \pgfplotspointaxisdirectionxy, then I get the computed X and Y coordinates and remember them into two global macros. These are used later-on.

  • Awesome ,Christian. Thanks so much for taking care of my issue. The approach you showed by code worked absolutely fine for me. I had to solve the non equal scaling of my X and Y axis with the axis option axis equal first. – goeck Dec 27 '14 at 14:08