With normal curves it works all fine, but what's about Bezier curves?
I have a Bezier curve of the kind (-0.3,3.7) .. controls (2.3,0.9) and ......
I want to set two coordinates on the Bezier-path und fill the area between x-axis and the part of the curve.
What do I have to make better?
\documentclass[margin=3mm, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
%\usepgfplotslibrary{patchplots}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
MyMarks/.style={
decoration={markings,
mark=at position 0.30 with {\coordinate[label=A] (A); \fill[red] circle [radius=2pt];},
mark=at position 0.55 with {\coordinate[label=B] (B); \fill[red] circle [radius=2pt];}
}, postaction={decorate},
},
]
\begin{axis}[
axis lines=middle,
xlabel=$x$, ylabel=$y$,
xlabel style = {anchor=north east},
ylabel style = {anchor=north east},
xtick=\empty, ytick=\empty,
clip=false,
xmin=0,xmax=10,
ymin=0, ymax=5,
]
% Curve
\draw[thick, red, name path=Curve,
MyMarks,
](-0.3,3.7) .. controls (2.3,0.9) and (3.1,3.9) .. (5.1,4) .. controls (6.5,4.1) and (6.5,3) .. (8.2,2)
node[black, above=15pt,pos=.9]{$f(x)$};
% "x values" of the Points A, B
\coordinate[label=below:Bz] (Bz) at ($(0,0)!(B)!(5,0)$);
\coordinate[label=below:Az] (Az) at ($(0,0)!(A)!(5,0)$);
% fill 1
\draw [cyan, ultra thick, name path=Line1] (A)--(Bz);
\addplot [orange] fill between [of=Curve and Line1,
soft clip={(Az) rectangle (B)}, % ????
];
% fill 2
\fill[orange!44] (Az) -- (Bz) -- (A) --cycle;
%% Annotations
\draw[dashed] (A) -- (Az) %node[below] {$a$}
(B) -- (Bz) %node[below] {$b$}
;
\end{axis}
\end{tikzpicture}
\end{document}
easily
.