如图所示,第一象限填充颜色下边界为绘制的曲线,如何填充?图像如下:
代码如下:documentclass[12pt]{article}
usepackage{tikz}
usepackage{amsmath}
begin{document}
\begin{tikzpicture}[samples=1000,scale=1.5,xscale=1, yscale=1]
\draw[thick,->] (-3.5,0) -- (3.5,0) node at(3.35,-0.2) {$x$};
\draw[thick,->] (0,-2.5) -- (0,2.5) node at(0.2,2.3) {$y$};
\draw[semithick,domain=-1.25:1.25]plot({tan(\x r)},\x);
\draw[dashed](-3,pi/2)--(3,pi/2)(-3,-pi/2)--(3,-pi/2);
\fill[red!30,opacity=0.3] (0,0)--({tan(\x r)},\x)--(2.8,pi/2) --(0,pi/2) --(0,0)-- cycle;
\end{tikzpicture}
end{document}
可以利用pgfplots的方法实现...建议参考pgfplots文档P104的做法。下面是MWE和效果。
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
axis lines=middle,
axis on top,
xtick = \empty,
ytick = \empty,
xlabel = {$x$},
ylabel = {$y$},
xmin=-2.0, xmax=2.0,
ymin=-2.5, ymax=2.5,
samples=1000]
\addplot[semithick,name path=A] ({x},{rad(atan(x))});
\path[name path=B] (0,pi/2) -- (1.8,pi/2);
\draw[dashed](-3,pi/2)--(3,pi/2)(-3,-pi/2)--(3,-pi/2);
\addplot[red!30,opacity=.3] fill between[of=A and B,soft clip={
(0,0) rectangle (1.8,2)
}];
\end{axis}
\end{tikzpicture}
\end{document}
\fill
需要一条封闭路径
\fill[red!30,opacity=0.3] (0,0)-- plot[domain=0:1.25] ({tan(\x r)},\x)--(3, pi/2) -- (0, pi/2) -- cycle;
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[samples=1000,scale=1.5,xscale=1, yscale=1]
\draw[thick,->] (-3.5,0) -- (3.5,0) node at(3.35,-0.2) {$x$};
\draw[thick,->] (0,-2.5) -- (0,2.5) node at(0.2,2.3) {$y$};
\draw[semithick,domain=-1.25:1.25]plot({tan(\x r)},\x);
\draw[dashed](-3,pi/2)--(3,pi/2) (-3,-pi/2)--(3,-pi/2);
\fill[red!30,opacity=0.3] (0,0)-- plot[domain=0:1.25] ({tan(\x r)},\x)--(3, pi/2) -- (0, pi/2) -- cycle;
\end{tikzpicture}
\end{document}
更简洁而且更直接的做法!而且fill between也更加耗时