4

I have the following latex code:

 \begin{tikzpicture}
  \begin{axis}[ 
    xlabel=Strike Price (K),
    ylabel={Put Value (p)}
  ] 
   \addplot [only marks=*,blue] plot coordinates {
   (40,10)
   (50,20)
   (70,30)
   }; 
    \addplot [smooth=*,red] plot coordinates {
   (40,10)
   (70,30)
   }; 
  \end{axis}
\end{tikzpicture}

I want to connect the two end points with any convex function, and then shade the area in between that function and the current line, not too sure how to do this though.

5

You can use fillbetween library to fill the area. To make one of the curves curved, I have used smooth option.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{fillbetween}
\begin{document}
   \begin{tikzpicture}
  \begin{axis}[
    xlabel=Strike Price (K),
    ylabel={Put Value (p)}
  ]
   \addplot [mark=*,blue,smooth,name path=A] plot coordinates {
   (40,10)
   (50,20)
   (70,30)
   };
    \addplot [mark=o,red,name path=B] plot coordinates {
   (40,10)
   (70,30)
   };
   \addplot[olive!40] fill between[of=A and B];
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Or may be this, with the lines commented

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{fillbetween}
\begin{document}
   \begin{tikzpicture}
  \begin{axis}[
    xlabel=Strike Price (K),
    ylabel={Put Value (p)}
  ] 
   %% the upper curve
   \addplot [mark=*,blue,smooth,name path=A] plot coordinates {
   (40,10)
   (50,20)
   (70,30)
   };
   %% The lower curve
   \addplot [no marks,green,smooth,name path=B] plot coordinates {
   (40,10)
   (60,15)
   (70,30)
   };
   %% the straight line
    \addplot [mark=o,red,name path=C] plot coordinates {
   (40,10)
   (70,30)
   };
   %% filling
   \addplot[olive!40] fill between[of=B and C];
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks! could you explain specifically which line actually gives us the new function? is it just the mark=*? I actually wnated a convex function that went through some point such as (60,15) for example, how would i go about doing that? – dimebucker91 May 4 '15 at 8:13
  • @dimebucker91 You want the curve on the lower side? – user11232 May 4 '15 at 8:14
  • yeah, Im trying to show that the feasible values for p are on the right hand side of the red line, and that the middle point is obviously way outside the feasible bundles – dimebucker91 May 4 '15 at 8:18
  • @dimebucker91 See the edit. I have added comments to show the curves in the code. – user11232 May 4 '15 at 8:19
  • 1
    @dimebucker91 Add no marks in \addplot [no marks,green,smooth,name path=B] plot coordinates {... – user11232 May 4 '15 at 8:20

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.