我需要给条带上色。函数是 $y = \frac{1}{x}$ 我可以画图,但不能给条带上色\;\
\begin{center}
\begin{tikzpicture}
\draw[->] (-1,0) -- (7,0) node[right] {$x$};
\draw[->] (0,-1) -- (0,4) node[above] {$y$};
\draw[scale=1.5,domain=0.35:4,smooth, variable=\x,black, ultra thick] plot ({\x},{1/(\x)});
\draw[dashed] (3,0)--(3,0.75);
\draw[dashed] (0,0.75)--(3,0.75);
\node at (-0.5,0.75){$\frac{1}{b}$};
\node at (3,-0.3){$b$};
\node at (1,-0.3){$a$};
\node at (-0.5,2.2) {$\frac{1}{a}$};
\draw[dashed] (1,0)--(1,2.2);
\draw[dashed] (0,2.2)--(1,2.2);
\node at (1,2.2) {$\bullet$};
\node at (3,0.75) {$\bullet$};
\end{tikzpicture}
\end{center}
答案1
带有软件包的解决方案mfpic
,适用于可能感兴趣的 MetaPost(和 METAFONT)的 LaTeX 界面。
填充是通过以下指令实现的
\gfill[.5(red+white)]\btwnfcn{1, 3, .1}{0}{f(x)}
\btwnfcn
0
产生由两个函数(这里和f(x)
)和垂直线(这里是方程x=1
和)形成的闭合路径x=3
,然后对其进行填充。
请注意,由于 OP 示例中的函数路径按 1.5 倍缩放,因此我倾向于将其定义f(x)
为等于2.25/x
而不是1/x
。它产生的路径与缩放相同,并且以这种方式处理它要容易得多。
\documentclass[border=2mm]{standalone}
\usepackage[metapost, mplabels, truebbox]{mfpic}
\mfpverbtex{%&latex
\documentclass{article}
\usepackage{amsmath}
\begin{document}}
\setlength{\mfpicunit}{1cm}
\opengraphsfile{\jobname}
\begin{document}
\begin{mfpic}[1]{-1}{7}{-1}{5}
\fdef{f}{x}{2.25/x}
\gfill[.5(red+white)]\btwnfcn{1, 3, .1}{0}{f(x)}
\dashed\lines{(1, 0), (1, f(1)), (0, f(1))}
\dashed\lines{(3, 0), (3, f(3)), (0, f(3))}
\doaxes{xy}
\penwd{1.2bp}
\function{.5, 6, .1}{f(x)}
\tlpointsep{3bp}
\tlabels{[tr]{origin}{$O$} [tc]{(\xmax, 0)}{$x$} [cr]{(0, \ymax)}{$y$}
[tc]{(1, 0)}{$a$} [tc]{(3, 0)}{$b$}
[cr]{(0, f(1))}{$\dfrac{1}{a}$} [cr]{(0, f(3))}{$\dfrac{1}{b}$}}
\end{mfpic}
\closegraphsfile
\end{document}
先运行 (PDF)LaTeX,然后运行 MetaPost,最后再次运行 (PDF)LaTeX。输出:
答案2
只需在曲线下方填充即可。
\documentclass[10pt,letterpaper]{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\fill [red!50, domain=1:3, variable=\x]
(1, 0)
-- plot ({\x}, {2.2/(\x)})
-- (3, 0)
-- cycle; \draw[->] (-1,0) -- (7,0) node[right] {$x$};
\draw[->] (0,-1) -- (0,4) node[above] {$y$};
\draw[scale=1.5,domain=0.35:4,smooth, variable=\x,black, ultra thick] plot ({\x},{1/(\x)});
\draw[dashed] (3,0)--(3,0.75);
\draw[dashed] (0,0.75)--(3,0.75);
\node at (-0.5,0.75){$\frac{1}{b}$};
\node at (3,-0.3){$b$};
\node at (1,-0.3){$a$};
\node at (-0.5,2.2) {$\frac{1}{a}$};
\draw[dashed] (1,0)--(1,2.2);
\draw[dashed] (0,2.2)--(1,2.2);
\node at (1,2.2) {$\bullet$};
\node at (3,0.75) {$\bullet$};
\end{tikzpicture}
\end{center}
\end{document}