如何对标准抛物线和平方根函数所包围的区域进行着色?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\raisebox{0mm}[0mm][0mm]
{
\begin{tikzpicture}
\begin{axis}[width=2.25in, height=2.25in, axis equal image, axis on top, clip=false,
axis lines=middle,
xmin=-2,xmax=4, domain=-2:4,
ymin=-0.75,ymax=4,
restrict y to domain=-0.75:4,
xtick={\empty},ytick={\empty},
axis lines=middle,
axis line style={latex-latex},
xlabel=\textit{x},ylabel=\textit{y},
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]
%The graphs of the square root function and the standard parabola are plotted.
\addplot[samples=501, domain=-2:2] {x^2};
\addplot[samples=501, domain=0:4] {sqrt(x)};
%Coordinate A is the point of tangency to the graph of the standard parabola, and B is the
%x-intercept of the tangent line.
\coordinate (A) at (-15/8,225/64);
\coordinate (B) at (-15/16,0);
%Coordinate P is the point of tangency to the graph of the square root function, and Q is
%the y-intercept of the tangent line.
\coordinate (P) at (15/4,{sqrt(15/4)});
\coordinate (Q) at (0,{1/4*sqrt(15)});
\end{axis}
%A "pin" is drawn to A.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A)!0.5cm!-90:(B)$) node[anchor=west, inner sep=0, font=\scriptsize]{\makebox[0pt][r]{$y=x^{2}$}};
%A "pin" is drawn to P.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (P) -- ($(P)!0.5cm!90:(Q)$);
\node[anchor=north, inner sep=0, outer sep=0, font=\scriptsize] at ($(P)!0.4cm!90:(Q)$){\makebox[0pt][l]{$y=\sqrt{x}$}};
\end{tikzpicture}
}
\end{document}
答案1
这是图书馆的一项标准任务fillbetween
。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\begin{document}
\raisebox{0mm}[0mm][0mm]
{
\begin{tikzpicture}
\begin{axis}[width=2.25in, height=2.25in, axis equal image, axis on top, clip=false,
axis lines=middle,
xmin=-2,xmax=4, domain=-2:4,
ymin=-0.75,ymax=4,
restrict y to domain=-0.75:4,
xtick={\empty},ytick={\empty},
axis lines=middle,
axis line style={latex-latex},
xlabel=\textit{x},ylabel=\textit{y},
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]
%The graphs of the square root function and the standard parabola are plotted.
\addplot[samples=501, domain=-2:2,name path=parabola] {x^2};
\addplot[samples=501, domain=0:4,name path=root] {sqrt(x)};
\addplot[red!10] fill between [of=parabola and root, soft clip={domain=0:1}];
%Coordinate A is the point of tangency to the graph of the standard parabola, and B is the
%x-intercept of the tangent line.
\coordinate (A) at (-15/8,225/64);
\coordinate (B) at (-15/16,0);
%Coordinate P is the point of tangency to the graph of the square root function, and Q is
%the y-intercept of the tangent line.
\coordinate (P) at (15/4,{sqrt(15/4)});
\coordinate (Q) at (0,{1/4*sqrt(15)});
\end{axis}
%A "pin" is drawn to A.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A)!0.5cm!-90:(B)$) node[anchor=west, inner sep=0, font=\scriptsize]{\makebox[0pt][r]{$y=x^{2}$}};
%A "pin" is drawn to P.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (P) -- ($(P)!0.5cm!90:(Q)$);
\node[anchor=north, inner sep=0, outer sep=0, font=\scriptsize] at ($(P)!0.4cm!90:(Q)$){\makebox[0pt][l]{$y=\sqrt{x}$}};
\end{tikzpicture}
}
\end{document}