我目前想要对区域 S_{2} 进行着色,该区域是由曲线 y=g(x) 和直线 y=10 和 y=4 所包围的区域。现在,我正在使用以下代码,但是如何使用填充函数来执行此操作?
\documentclass[]{article}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepgfplotslibrary{fillbetween}
\begin{document}
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
ticks=none,
grid=none,
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmin=-5,xmax=15,
ymin=-5,ymax=15,
scale=1.5,
transform shape
]
\plot[name path=f1,thick,samples=100,domain=2.1:14.5] {3-2/(x-2)};
\plot[name path=f15,thick,opacity=0,samples=100,domain=2.75:14.5] {0};
\plot[name path=f2,thick,samples=100,domain=-5:2.9] {2+2/(3-x)};
\plot[name path=f25,thick,opacity=0,samples=100,domain=-3:5] {10};
\draw[thick,fill=black,opacity=0.7] (axis cs: 2.67,0) circle (0.7mm);
\draw[thick,fill=black,opacity=0.7] (axis cs: 0,2.67) circle (0.7mm);
%
\addplot fill between[
of = f1 and f15,
soft clip={domain=4:10},
every even segment/.style = {gray,opacity=.4}
];
%
\addplot fill between[
of = f2 and f25,
soft clip={domain=0:2.75},
every even segment/.style = {gray,opacity=.4}
];
%%
%,domain y=1:2%
%\draw[style=dashed] (axis cs:1,-20)--(axis cs:1,20);
\node [above] at (axis cs: -0.4,0) {$O$};
\node [above] at (axis cs: 10,3) {$y=f(x)$};
\node [right] at (axis cs: 3,10) {$y=g(x)$};
%
\node [right] at (axis cs: 6,1) {$S_{1}$};
\node [right] at (axis cs: 1,6) {$S_{2}$};
%\\
\node [below] at (axis cs: 10,0) {$x_{1}$};
\node [below] at (axis cs: 4,0) {$4$};
%
\node [left] at (axis cs: 0,4) {$4$};
\node [left] at (axis cs: 0,10) {$y_{1}$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
任何帮助,将不胜感激。
非常感谢!
答案1
非常简单:引入另一个f26
带有 的虚拟函数\plot[name path=f26,thick,opacity=0,samples=100,domain=-5:2.9] {2+2/(3-max(x,2))};
,然后阴影部分位于 y 轴f25
和之间的区域f26
。
\documentclass[]{article}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepgfplotslibrary{fillbetween}
\begin{document}
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
ticks=none,
grid=none,
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmin=-5,xmax=15,
ymin=-5,ymax=15,
scale=1.5,
transform shape
]
\plot[name path=f1,thick,samples=100,domain=2.1:14.5] {3-2/(x-2)};
\plot[name path=f15,thick,opacity=0,samples=100,domain=2.75:14.5] {0};
\plot[name path=f2,thick,samples=100,domain=-5:2.9] {2+2/(3-x)};
\plot[name path=f26,thick,opacity=0,samples=100,domain=-5:2.9] {2+2/(3-max(x,2))};
\plot[name path=f25,thick,opacity=0,samples=100,domain=-3:5] {10};
\draw[thick,fill=black,opacity=0.7] (axis cs: 2.67,0) circle (0.7mm);
\draw[thick,fill=black,opacity=0.7] (axis cs: 0,2.67) circle (0.7mm);
%
\addplot fill between[
of = f1 and f15,
soft clip={domain=4:10},
every even segment/.style = {gray,opacity=.4}
];
%
\addplot fill between[
of = f26 and f25,
soft clip={domain=0:2.75},
every even segment/.style = {gray,opacity=.4}
];
%%
%,domain y=1:2%
%\draw[style=dashed] (axis cs:1,-20)--(axis cs:1,20);
\node [above] at (axis cs: -0.4,0) {$O$};
\node [above] at (axis cs: 10,3) {$y=f(x)$};
\node [right] at (axis cs: 3,10) {$y=g(x)$};
%
\node [right] at (axis cs: 6,1) {$S_{1}$};
\node [right] at (axis cs: 1,6) {$S_{2}$};
%\\
\node [below] at (axis cs: 10,0) {$x_{1}$};
\node [below] at (axis cs: 4,0) {$4$};
%
\node [left] at (axis cs: 0,4) {$4$};
\node [left] at (axis cs: 0,10) {$y_{1}$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}