I would like to fill the area under the rectangles that have the origin and the working point (Q_1, H_1)
and (Q_2, H_2)
, respectively, obtained as intersections between the two red curves with the blue one.
I managed to pinpoint the intersection point and to draw the segments defining the rectangle, and then I tried to use fill between
but the output was coloured trapezoid between the segment and the whole horizontal axis.
I started thinking the missing element is the right end-point of the interval over which the horizontal axis path is defined (which has to be Q_1
and not xmax
), so I looked for a solution to this problem, without any relevant success.
I am not very familiar with this package (that is the reason why maybe this question is almost a duplicate but I cannot determine it), so I have not been able to use properly let
or pgfextractx
functions for this purpose.
How can I reference symbolically the abscissa of the intersection point (OP1)
and use it for defining properly the useful interval for fill between
?
Here follows my attempt:
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta,babel,calc,intersections}
\usepgfplotslibrary{fillbetween}
\begin{figure}[H] %% figure is closed
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=1, ymin=0, ymax=1.5,
axis x line=middle,
axis y line=middle,
xlabel=$Q$,ylabel=$H$,
ticks=none,
]
\addplot[name path =pump,blue,domain=0:1] {-0.5*x^2+1};
\addplot[red,domain=0:1,name path=load1] {0.5*x^2+0.4*x+0.5};
\addplot[red,domain=0:1,name path=load2] {2*x^2+1.6*x+0.5};
\path [name intersections={of=load1 and pump}];
\coordinate [label= ${(Q_1,H_1)}$ ] (OP1) at (intersection-1);
\path [name intersections={of=load2 and pump}];
\coordinate [label= ${(Q_2,H_2)}$ ] (OP2) at (intersection-1);
\draw[name path=opv1] (OP1) -- (OP1|-0,0);
\draw[name path=oph1] (OP1) -- (0,0 |- OP1);
\draw[name path=opv2] (OP2) -- (OP2|-0,0);
\draw[name path=oph2] (OP2) -- (0,0 |- OP2);
\path[name path=zero]
(\pgfkeysvalueof{/pgfplots/xmin},0) --
(\pgfkeysvalueof{/pgfplots/xmax},0);
\addplot[orange]fill between[of=oph1 and zero];
\end{axis}
\foreach \point in {OP1,OP2}
\fill [red] (\point) circle (2pt);
\end{tikzpicture}
\end{center}
\caption{System working point}
\end{figure}