0

I wish to draw a radius in circle as below:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    legend pos=outer north east,
    legend cell align={left},
    grid, grid style=dashed,
    xmin=0,xmax=1.2,
    ymin=0,ymax=1.2,
    ytick={0,0.2,...,1.2},
    xtick={0,0.2,...,1.2},
    extra y ticks={0.5},
    extra x ticks={0.5},
    axis lines = middle,
    set layers,
    xlabel={$x$},ylabel={$y$}, 
    x label style={at={(1,0)},right},
    y label style={at={(0,1)},above},
    x tick label style={
        tick label style={rotate=60},
        anchor=east
    },
    y tick label style={
        /pgf/number format/fixed,
        /pgf/number format/precision=1,
        /pgf/number format/fixed zerofill=true
    },
    axis equal,
    ]
    \node[fill,circle,minimum size=2pt,inner sep=0] at (axis cs:0.5,0.5) {};
    \draw[line width=1pt] (axis cs:0.5,0.5) circle (0.5);
    \draw (0.5,0.5) -- ++(0.5,0);
    \end{axis}
    \end{tikzpicture}
\end{document}

But the unit sounds like not as expected: enter image description here

2
  • Are you looking for \draw (axis cs:0.5,0.5) -- (axis cs:1,0.5);? Do you have any objections to using a newer version of pgfplots, where this is not necessary?
    – user194703
    Nov 2 '19 at 17:26
  • I think you need axis direction cs for relative coordinates, see e.g. tex.stackexchange.com/questions/332553/… Nov 2 '19 at 17:28
1

You are using an old version of pgfplots. So you need to prepend coordinates with axis cs:, as you did for the circle. Relative coordinates are even more tricky because (axis cs:0,0) may not be at (0,0) of the ambient tikzpicture, see Torbjørn's link. However, I would like to argue that in this case the advantage of using relative coordinates is, at best, minimal. So maybe, assuming you wish to keep the old compatibility mode,

\draw (axis cs:0.5,0.5) -- (axis cs:1,0.5);

is the easiest way to go.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    legend pos=outer north east,
    legend cell align={left},
    grid, grid style=dashed,
    xmin=0,xmax=1.2,
    ymin=0,ymax=1.2,
    ytick={0,0.2,...,1.2},
    xtick={0,0.2,...,1.2},
    extra y ticks={0.5},
    extra x ticks={0.5},
    axis lines = middle,
    set layers,
    xlabel={$x$},ylabel={$y$}, 
    x label style={at={(1,0)},right},
    y label style={at={(0,1)},above},
    x tick label style={
        tick label style={rotate=60},
        anchor=east
    },
    y tick label style={
        /pgf/number format/fixed,
        /pgf/number format/precision=1,
        /pgf/number format/fixed zerofill=true
    },
    axis equal,
    ]
    \node[fill,circle,minimum size=2pt,inner sep=0] at (axis cs:0.5,0.5) {};
    \draw[line width=1pt] (axis cs:0.5,0.5) circle[radius=0.5];
    % or circle[x radius=\x1,y radius=\y1];
    \draw (axis cs:0.5,0.5) -- (axis cs:1,0.5) node[midway,above]{$r$};
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

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.