为什么要这样画圆?我怎样才能最好地画圆?
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal=true,
axis lines=middle, enlargelimits=false,
xlabel={$x$}, ylabel={$y$},
%
xlabel style={at={(ticklabel* cs:0.983)},anchor=west},
ylabel style={at={(ticklabel* cs:1.03)}, anchor=north west, align=right},
%
tick style={},
%
x tick label style={below},
y tick label style={left},
%
xmin=-10, xmax=10,
ymin=-12, ymax=12,
xtick={}, ytick={},
xticklabels={}, yticklabels={},
%
after end axis/.code={
\path(axis cs:0,0)
node [anchor=north west,yshift=0 cm, xshift=0 cm] {}
node [anchor=north east,xshift=0 cm] {O};}]
%
\addplot[domain=-5:8,very thick,red,smooth] {4-x};
\addplot [domain=-10:10,,very thick, blue,samples=50,smooth] {4+sqrt(32-x^2)};
\addplot [domain=-10:10,,very thick, blue,samples=50,smooth] {4-sqrt(32-x^2)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以直接使用在您的内部\draw
绘制一个(就像已经circle
axis
由@DavidCarlisle 建议)。以下代码至少需要compat=1.11
(否则您将需要使用axis cs:0,4
定位并且可能需要调整圆半径),但compat=1.18
也适用于最新的。
(这是快点和更多准确的与使用一些样本相比)
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}% at least 1.11
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal=true,
axis lines=middle, enlargelimits=false,
xlabel={$x$}, ylabel={$y$},
%
xlabel style={at={(ticklabel* cs:0.983)},anchor=west},
ylabel style={at={(ticklabel* cs:1.03)}, anchor=north west, align=right},
%
tick style={},
%
x tick label style={below},
y tick label style={left},
%
xmin=-10, xmax=10,
ymin=-12, ymax=12,
xtick={}, ytick={},
xticklabels={}, yticklabels={},
%
after end axis/.code={
\path(axis cs:0,0)
node [anchor=north east,xshift=0 cm] {O};}]
\addplot[domain=-5:8,very thick,red,smooth] {4-x};
\draw[very thick,blue]
(0,4) circle[radius=sqrt(32)];
\end{axis}
\end{tikzpicture}
\end{document}
答案2
在这种简单的情况下使用普通的 TikZ 并不是一个坏主意。缩放是明确的,你可以直观地控制它,以及 x 轴和 y 轴的长度。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.4]
\draw[->] (-7,0)--(8,0) node[below]{$x$};
\draw[->] (0,-3)--(0,11) node[left]{$y$};
\path
(0,0) node[below left]{O}
(4,0) node[below]{$4$}
(0,4) node[right]{$4$}
;
% the circle x^2 + (y-4)^2 = 32
\draw[thick,teal] (0,4) circle({sqrt(32)});
% the line y=4-x from x=-6 to x=6
\draw[thick,magenta] (-6,10)--(6,-2);
\end{tikzpicture}
\end{document}