5

I want to fill the area of a region R bounded by x=f(y), x=g(y), y=A and y=B. For example, R is bounded by x=0, x=2/y, y=1 and y=4.

N.N.
  • 36,163
  • Does http://tex.stackexchange.com/questions/17517/fill-the-area-between-two-curves-calculated-by-pgfplots help? – Peter Grill Jun 22 '11 at 19:26

2 Answers2

10

A solution with TikZ :

\documentclass{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=2,domain=0.4:5] \draw[very thin,color=gray] (-0.1,-0.1) grid (5,5);
\draw[->] (-0.2,0) -- (5.2,0) node[right] (axex) {$x$};     \draw[->] (0,-0.2) -- (0,5.2) node[above] {$f(x)$};     
\draw[color=red,samples=100]    plot (\x,2/\x)  node[right] {$f(x) =\frac{2}{x}$};
\path[clip] (0,1) rectangle (5,4);    
\path[fill=gray!50,opacity=.5] (0,0)--(0,4)--plot (\x,2/\x)-|(axex)--cycle;
\end{tikzpicture}
\end{document} 

enter image description here

Alain Matthes
  • 95,075
4

run it with xelatex

\documentclass{article}
\usepackage{pst-plot}

\begin{document}

\psset{unit=2}
\begin{pspicture}(-0.5,-0.5)(3,5)
  \psclip{%
    \pscustom[linestyle=none,algebraic]{%
      \psplot{0.1}{2}{2/x}
      \psline(2,1)(0,1)(0,4)(2,4)
    }
  }
    \psframe[fillstyle=vlines,hatchcolor=blue,
             linestyle=none](0,0)(3,4)
  \endpsclip
  \psaxes{->}(0,0)(-.5,-.5)(3,5)
  \psplot[linewidth=1.5pt,algebraic,yMaxValue=4.1]{0.1}{3}{2/x}
\end{pspicture}

\end{document} 

enter image description here