以下是我正在使用的代码。基本上,我试图为两条曲线和直线之间的区域着色$y=1$
。$y=2$
当我使用填充时,我如何实际限制这些特定 y 值之间的区域?
多谢你们。
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{bigints}
\usepackage{color}
\usepgfplotslibrary{fillbetween}
\begin{document}
\setlength{\parindent}{0mm}
\textbf{c}
\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
ticks=none
}}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
samples=100,
domain=-4:1,
xmin=-2,xmax=3,
ymin=-3,ymax=5,
]
\addplot[name path=func1, black, thick, mark=none,domain=-2:2] {exp(x)};
\addplot[name path=func2,thick,domain=-2:3] {x};
%\addplot[fill=gray,opacity=.4,domain=0:1,samples=50] {sqrt(-1*x+1)}\closedcycle;
\addplot fill between[
of = func1 and func2,
soft clip={domain=0:2},
every even segment/.style = {gray,opacity=.4}
];
\draw[thick,dashed,brown] (axis cs:0,1) -- (axis cs:1,1);
\draw[thick,dashed,brown] (axis cs:0.693,2) -- (axis cs:2,2);
\node [below] at (axis cs: -3,0) {$-3$};
\node [right] at (axis cs: 0,-0.4) {$O$};
\node [left] at (axis cs: -0.2,1) {$1$};
\node [left] at (axis cs: -0.2,2) {$2$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
您可以使用domain y=<min>:<max>
:
代码:
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{bigints}
\usepackage{color}
\usepgfplotslibrary{fillbetween}
\begin{document}
\setlength{\parindent}{0mm}
\textbf{c}
\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
ticks=none
}}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
samples=100,
domain=-4:1,
xmin=-2,xmax=3,
ymin=-3,ymax=5,
]
\addplot[name path=func1, black, thick, mark=none,domain=-2:2] {exp(x)};
\addplot[name path=func2,thick,domain=-2:3] {x};
%\addplot[fill=gray,opacity=.4,domain=0:1,samples=50] {sqrt(-1*x+1)}\closedcycle;
\addplot fill between[
of = func1 and func2,
soft clip={domain=0:2,domain y=1:2},
every even segment/.style = {gray,opacity=.4}
];
\draw[thick,dashed,brown] (axis cs:0,1) -- (axis cs:1,1);
\draw[thick,dashed,brown] (axis cs:0.693,2) -- (axis cs:2,2);
\node [below] at (axis cs: -3,0) {$-3$};
\node [right] at (axis cs: 0,-0.4) {$O$};
\node [left] at (axis cs: -0.2,1) {$1$};
\node [left] at (axis cs: -0.2,2) {$2$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
result