# How to plot parabola in the selected segment using TikZ

I want to plot this: I know, that I can find intersections using TikZ (tried \shade but don't know how to plot parabola only in a segment), but I don't know how to plot this R figure, and S+T, and U+V. How can I plot this? New detail: How [domain] works?

\tipc{[x=1cm,y=1cm]

\def\xmin{0}
\def\xmax{10}
\def\ymin{0}
\def\ymax{10}
\draw[style=help lines, ystep=1, xstep=1] (\xmin,\ymin) grid
(\xmax,\ymax);

% axes
\draw (-.25,-.25) node[auto] {0};
\draw[->] (\xmin,\ymin) -- (\xmax,\ymin) node[right] {$Q$};
\draw[->] (\xmin,\ymin) -- (\xmin,\ymax) node[above] {$P$};
\draw[red] (2,2) parabola (8,8) node[right,black] {$S$};
\draw[blue] (8,2) parabola (2,8) node[left,black] {$D$};
\draw[dashed]  (5,0) node[below] {$q_A$} -- (5,3.5);
\draw[dashed] (3.72,-0.5) -- (3.72,2.5) -- (6.27,2.5) -- (6.27,-0.5);
\draw[<->] (3.72,-0.5) node [below] {$q_s$}  -- ++(2.55,0) node [midway,below] {$Im$}
node [below] {$q_d$};
\begin{scope}
\draw[color=red!30,domain=1.72:3]
(5,3.5) parabola  (2,8)  |- (3.72,3.5);
\end{scope}
} • I guess a nice tutorial for your purpose is TikZ for economists. Jan 24, 2013 at 10:17
• Just from looking at it, i would say this would be much easier to do with pgfplots (if you have mathematical expressions for the curves). You can handle the problem of getting the intersection with the sugestions from tex.stackexchange.com/questions/21408/intersections-in-pgfplots Jan 24, 2013 at 10:50
• I'm not sure if I've understand your question correctly... Do you want to create exactly the plot you've shown above? Jan 24, 2013 at 11:52
• It would be great. Jan 24, 2013 at 11:52
• @Ptech can you provide exact coordinates or and approximation of the plot would be ok? Jan 24, 2013 at 11:56

Here is my solution. Please note that I have not used the parabola function of tikz because I failed to define the domain (not the end-points) and instead plotted two quadratic functions:

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\def\xmin{0}
\def\xmax{10}
\def\ymin{0}
\def\ymax{10}
\draw[style=help lines, ystep=1, xstep=1] (\xmin,\ymin) grid
(\xmax,\ymax);

\draw (-.25,-.25) node[auto] {0};
\draw[->] (\xmin,\ymin) -- (\xmax,\ymin) node[right] {$Q$};
\draw[->] (\xmin,\ymin) -- (\xmin,\ymax) node[above] {$P$};

\def\intersectX{4.76}
\def\intersectY{4.26}
\def\QPX{4}
\def\QPY{5}
\draw[color=red] plot [domain=0:8] (\x,{((\x)^2)/10 +2)});
\draw[color=blue] plot [domain=0:8] (\x,{((\x-14)^2)/20)});

\fill[fill=pink,opacity=0.7] (0,\QPY) -- plot [domain=0:\QPY] (\x,{((\x-14)^2)/20)}) -- (\QPX,\QPY) -- cycle;
\fill[fill=cyan,opacity=0.7] (0,\QPY) -- plot [domain=0:\QPX] (\x,{((\x)^2)/10 +2)}) -- (\QPX,\QPY) -- cycle;

\draw [domain=\QPX:\intersectX]
plot(\x,{((\x-14)^2)/20)}) -- (\QPX,\QPY) -- (\QPX,\QPY) -- cycle;

\draw [fill=green,opacity=0.7,domain=\QPX:\intersectX]
plot(\x,{((\x)^2)/10 +2)}) -- (\QPX,\QPY) -- cycle;

\draw[dashed]  (\intersectX,0) node[below] {$Q_1$} -- (\intersectX,\intersectY);
\draw[dashed]  (0,\intersectY) node[below] {$P_1$} -- (\intersectX,\intersectY);
\draw[dashed]  (0,\intersectY) node[below] {$P_1$} -- (\intersectX,\intersectY);
\draw[dashed]  (\QPX,0) node[below] {$Q_2$} -- (\QPX,\QPY);
\draw[dashed]  (0,\QPY) node[below] {$P_2$} -- (\QPX,\QPY);

\end{tikzpicture}
\end{document}


Resulting in this: I used some help from this answer as well.

• This answer is great, I think, that i should get rid of parabola in tikz, and use plot instead (I had this question because parabola doesn't understand [domain]) Jan 24, 2013 at 13:54