2

The following is the code I am using. Basically, I am trying to shade the area between the two curves and the lines $y=1$ and $y=2$. When I use fill between, how do i actually restrict this between these particular y values?

Thanks guys.

\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}

result

4

You can use domain y=<min>:<max>:

enter image description here

The code:

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.