我希望绘制一个圆形的半径,如下图所示:
\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}
答案1
您使用的是旧版本的pgfplots
。因此,您需要在坐标前加上axis cs:
,就像您对圆所做的那样。相对坐标更加棘手,因为(axis cs:0,0)
可能不在(0,0)
环境 处tikzpicture
,请参阅Torbjørn 的链接。但是,我想说的是,在这种情况下,使用相对坐标的优势最多只能说是微不足道。所以,假设你希望保留旧的兼容模式,
\draw (axis cs:0.5,0.5) -- (axis cs:1,0.5);
是最简单的方法。
\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}