编辑1
我稍微修改了一下代码。此代码有效:
\addplot[name path=A,domain=-0.236:4.236, solid, blue] {sqrt(5-(x-2)^2)};
\addplot [name path=C, line width=0.05pt] coordinates { (-0.236,5) (4.236,5) };
\addplot [teal!20] fill between [of=A and C];
无视后面的水印
[![在此处输入图片描述][1]][1]
我正在尝试绘制此图。MWE 为:
\documentclass[a4paper]{standalone}
\begin{document}
\[
\begin{tikzpicture}
\begin{axis}[axis lines=middle,
width=10cm,
height=10cm,
xlabel=$x$,
ylabel=$y$,
enlargelimits,
xtick={-2, -1,...,5,6},
ytick={-2,-1,...,3,4},
domain=-2:6,
samples=100,
xmin=-2,
xmax=6,
ymin=-2,
ymax=4,
]
\addplot[name path=B,domain=-2:6, dashed, blue, transparent] {4};
\addplot[name path=A,domain=-3:3, dashed, blue] {sqrt(x)};
\addplot [name = path=J, dashed, blue]coordinates {(1,6) (1,-6)};
\addplot[name path=H,blue,domain={-4:4}, solid, line width=1pt] {-5};
\addplot[red, fill opacity=0.20] fill between [of=B and A,soft clip=
{domain=-\sqrt{5}+2:\sqrt{5}+2}];
\end{axis}
\end{tikzpicture}
\]
\end{document}
[1]: https://i.stack.imgur.com/2Iu4V.png
答案1
这是你想要的:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17,
}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta}
\begin{document}
\pgfdeclarelayer{pre main}
\begin{tikzpicture}
\begin{axis}[width=100mm, height=100mm,
axis lines=middle,
axis line style= {-Straight Barb},
axis on top,
grid=both,
minor tick num=4,
minor grid style={very thin},
xlabel=$x$,
ylabel=$y$,
xmin=-0.5, xmax=4.5,
ymin=-0.5, ymax=4.5,
tick style=black,
tick label style = {inner sep=1pt, font=\scriptsize},
every axis plot post/.append style={draw=teal, very thick},
no marks,
samples=201,
]
\addplot [name path=A,domain=-5:5] {sqrt(4.84-(x-2)^2)};
\path [name path=B] (-0.2,4.5) -- (4.2,4.5);
\addplot [teal!30] fill between [of=A and B,
];
\end{axis}
\end{tikzpicture}
\end{document}