7

I'm trying to draw an arc (the top half of a circle of radius 8, centered at (-8,0)) but I can't figure out how to specify the radius in pgfplots's coordinate system. Here's a MWE:

\pgfplotsset{compat=1.5.1}
\begin{tikzpicture}
  \begin{axis}[
      xmin=-20,xmax=20,
    ]
    \addplot{x}; % not important, just to make things show up
    \draw (axis cs:-16,0) arc[start angle=180, end angle=0,
                              radius=8];
  \end{axis}
\end{tikzpicture}

I read about axis direction cs in the pgfplots manual, but it doesn't explain how to use it to calculate a distance like a radius -- it only says that for ellipses, it's done automatically. But I don't have an ellipse, I have an arc.

How can I specify a radius of 8 for my arc, using the coordinate system of my plot?

  • Oops, this (mostly) a duplicate of tex.stackexchange.com/questions/60220/…, and the disabledatascaling solution there works for me. But I would still like to know if it's possible to use axis direction cs for this. – Dan Drake Jun 11 '14 at 16:05
5

You can transform the distance for the radius using the function transformdirectionx (which is the math parser equivalent to \pgfplotstransformdirectionx):

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
      xmin=-10,xmax=10,
      axis equal,
      grid=both
    ]
    \addplot{x};
    \draw [ultra thick] (axis cs:0,-5) arc[start angle=-90, end angle=180,
                              radius={transformdirectionx(5)}];
  \end{axis}
\end{tikzpicture}
\end{document}
  • It seems that this solution brings dram flaws with it when using pgfplots v1.11. The calculated radius is way off at least in my actual case. As far as I know v1.11 brings some changes with handling of axis coordinate system and its transformations. Don't have a proper solution to asked question the right now anymore, since the proposed solution doesnt work. – goeck Jan 6 '15 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.