2

This is a follow-up question to Area between curves.

After one day, i found out how to do it in LaTeX (Miktex):

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\begin{document}
\begin{pspicture}(-3.5,-0.5)(4,7)
\begin{psclip}{
      \psplot[linestyle=none,algebraic,plotpoints=2000]{-3}{3}{x^2+1}%
       \psline[linestyle=none,algebraic,plotpoints=2000](-1,1)(-1,2)(2,5)(2,1)
  }%
       \psframe*[linecolor=cyan,fillstyle=solid](-1,1)(2,5)
\end{psclip}
   \psplot[algebraic,plotpoints=2000,yMaxValue=5.6]{-2.3}{2.3}{x^2+1}
    \psplot[algebraic,plotpoints=2000]{-3.5}{2.5}{x+3}
\psaxes{->}(0,0)(-3.5,-.9)(4,6.5)
\uput[-90](3.9,-.2){$x$}
\uput[-135](-.2,6.7){$y$}
\end{pspicture}
\end{document}

Area between graphs of two functions

Strange that the followwing code doesn't work:

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\begin{document}
\begin{pspicture}(-3.5,-0.5)(4,7)
\begin{psclip}{
      \psplot[linestyle=none,algebraic,plotpoints=2000]{-1.2}{2.2}{x^2+1}%
       \psplot[linestyle=none,algebraic,plotpoints=2000]{-1.2}{2.2}{x+3}
  }%
       \psframe*[linecolor=cyan,fillstyle=solid](-1,1)(2,5)
\end{psclip}
   \psplot[algebraic,plotpoints=2000,yMaxValue=5.6%,linecolor=cyan
    ]{-2.3}{2.3}{x^2+1}
    \psplot[algebraic,plotpoints=2000]{-3.5}{2.5}{x+3}
\psaxes{->}(0,0)(-3.5,-.9)(4,6.5)
\uput[-90](3.9,-.2){$x$}
\uput[-135](-.2,6.7){$y$}
\end{pspicture} 
\end{document}

Looks like the problem is with functions like f(x)= ax + b.

Am i correct?

  • 4
    what is the question? – David Carlisle Feb 15 '15 at 15:45
  • Welcome to TeX.SX! As David said, it would be helpful to know what the question is. When you do edit your question, if you can, please a minimal working example (MWE). – Adam Liter Feb 15 '15 at 15:54
  • I took the liberty of pasting the question from the deleted message you sent before. Just linking is not sufficient. – egreg Feb 15 '15 at 16:16
  • I suppose the underlying question is: why replacing the line \psline[linestyle=none,algebraic,plotpoints=2000](-1,1)(-1,2)(2,5)(2,1) by \psplot[linestyle=none,algebraic,plotpoints=2000]{-1.2}{2.2}{x+3} makes the filling of the area stop working? No idea for my part… – Franck Pastor Feb 15 '15 at 17:11
  • Yes David, perfect and thank you. I tried another functions and everything worked fine. But for functions like f(x) = ax + b, filling of the area don't works. – Ulysses Feb 15 '15 at 19:02
3

Wrap the curves used in the psclip inside a \pscustom, and make sure the enclose a space. To that end I've swapped the start/end points for the linear function x+3:

enter image description here

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\begin{pspicture}(-3.5,-0.5)(4,7)
  \begin{psclip}{
    \pscustom[linestyle=none,algebraic,plotpoints=2000]{
      \psplot{-1.2}{2.2}{x^2+1}%
      \psplot{2.2}{-1.2}{x+3}
    }
  }%
    \psframe*[linecolor=cyan,fillstyle=solid](-1,1)(2,5)
  \end{psclip}
  \psplot[algebraic,plotpoints=2000,yMaxValue=5.6%,linecolor=cyan
    ]{-2.3}{2.3}{x^2+1}
  \psplot[algebraic,plotpoints=2000]{-3.5}{2.5}{x+3}
  \psaxes{->}(0,0)(-3.5,-.9)(4,6.5)
  \uput[-90](3.9,-.2){$x$}
  \uput[-135](-.2,6.7){$y$}
\end{pspicture} 

\end{document}
  • Thanks a lot Werner. I enjoy this forum and it is helping me to write my Master's thesis about PSTricks and it's usage for courseware production. – Ulysses Feb 15 '15 at 19:22

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.