0

I was just wondering if the type of figures below can be drawn using Latex. I am not sure if Matlab is used but it is a simple graph showing concavity of a curve and then the shaded area in which the two curves intersect. It seems like an overkill to do this on Matlab, but that's just me.

If there are any resources that you guys can help with to learn more about how to draw these types of graphs on Latex.

enter image description here

Torbjørn T.
  • 206,688
OGC
  • 809
  • 3
    The answer to the question in the title is "yes", as for resources see https://tex.stackexchange.com/questions/15779/materials-for-learning-tikz I would think you could learn most of what you need for that figure from the first tutorial in the TikZ manual (chapter 2). The shading is perhaps the only thing you wouldn't learn from that. – Torbjørn T. Apr 30 '20 at 21:12
  • @TorbjørnT. Great resource! Thanks! – OGC Apr 30 '20 at 21:49

1 Answers1

4

It would help a lot if you post what you have tried, or content yourself with a plot that has less texts. Otherwise you make those who answer this punch in a lot of stuff.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{backgrounds,intersections}
\begin{document}
\begin{tikzpicture}[nodes={text height=0.7em,text depth=0.25ex}]
 \draw[name path=arc] (4,0)  arc[start
 angle=0,end angle=180,radius=2]
    node[pos=0.1,above right]{$\alpha\, W(y)$};
 \draw[name path=curve] (0,0) coordinate (O)to[out=-90,in=-135] (1,0) coordinate (x)
    -- ++ (45:4) node[right] {$P(y)$};
 \draw[name path=line] (0,2) coordinate (b)node[left]{$b$} -| (2,0) node[below] {$y^*$};    
 \draw[name intersections={of=curve and line,by=a}] (a) -- (O|-a)
     node[left]{$a$};
 \draw (0,4) node[above left] {$y$} |- (5,0) node[below left] {$x$};
 \begin{scope}[on background layer]
  \draw[name intersections={of=curve and arc,by={aux,i}}];
  \clip (current bounding box.south west) rectangle (i|-b);
  \fill[gray!20] (4,0)  arc[start angle=0,end angle=180,radius=2] 
   to[out=-90,in=-135] (x)  -- ++ (45:4);
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

As usual, there is a multitude of ways you can achieve this. Here is a way without libraries. (And yes, I think that my arc/.style={insert path={...}} is slightly better than \def\MyArc{...} but as long as these \defs are inside the tikzpicture they are not terrible.)

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[nodes={text height=0.7em,text depth=0.25ex},
    my arc/.style={insert path={(4,0)  arc[start angle=0,end angle=180,radius=2]}},
    my curve/.style={insert path={(0,0) to[out=-90,in=-135] (1,0) -- ++ (45:4)}}]
 \begin{scope}
  \clip[my curve] -| cycle;
  \fill[gray!20,my arc] -- ++ (0,-1) -- ++ (4,0);
 \end{scope}
 \draw (0,4) node[above left] {$x$} |- (5,0) node[below left] {$y$};
 \draw[my arc] node[pos=0.1,above right]{$\alpha\, W(y)$};
 \draw[my curve] node[right] {$P(y)$};
 \draw (0,2) node[left]{$b$} -| (2,0) node[below] {$y^*$}
  (0,1) node[left]{$a$} -- (2,1) node[above left]{bla}; 
\end{tikzpicture}
\end{document}

enter image description here

  • @Schroinder's cat Thanks for showing me how to do it in Latex. My question was more about directing me to a resource on how I would be able to do it. – OGC Apr 30 '20 at 21:51
  • 2
    @OGC The pgf manual is a decent resource. There is no super simple short cut to this graph, I think, because you probably need a library unless you wan to compute the intersections analytically. (To only shade the area you do not need a library, though, you can just use clips.) –  Apr 30 '20 at 21:54