I would really like to have a simple explanation to how the path and fill functions work in TikZ.
For instance, I don't know why I am unable to fill the whole area under the curve despite putting a line like this :
plot ({\x}, {2*exp(-\x/5)+ 1/2}) |- (0,0) ;
\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}
\usepackage{pgf, tikz, adjustbox}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, fill, inner sep=2.0pt, node contents={}},
every label/.append style = {label distance =2pt, inner sep=1pt, fill=white},
samples = 101,
domain = 0:10
]
\draw[-stealth] (-2.5, 0) -- (13, 0) node[right] {$\infty$}; % x-axis
\draw[-stealth] (0, -0.5) -- ( 0,4.3) node[above] {$\underline{e}_z$}; % y-axis
\foreach \i in {-2,-1,0, ...,12}
\draw (\i, 1mm) -- ++ (0,-2mm);
\draw[very thick, blue]
plot ({\x}, {2*exp(-\x/5) + 1/2}) -- (11,0.75);
% \fill [gray, domain=0:10, variable=\x]
% (0, 0)
% -- plot ({\x}, {2*exp(-\x/5)+ 1/2})
% -- (11, 0)
% -- cycle;
\path[pattern={Lines[angle=45,distance={3pt},
line width=0.2pt]},
pattern color=blue]
plot ({\x}, {2*exp(-\x/5)+ 1/2}) |- (0,0) ;
\path (11,0.75) node[red,dot,label = right:$h_\infty$];
\path (0,0) node[black,dot,scale =0.75,label=below left:$L$];
\end{tikzpicture}
\end{document}
I don't understand how the filling process works. For example if I try the \fill
function:
\fill [gray, domain=0:10, variable=\x]
(0, 0)
-- plot ({\x}, {2*exp(-\x/5)+ 1/2})
-- (11, 0)
-- cycle;
With (11,0) the last point of the curve then I get this :
It's more a general question about how to use the filling process very simply and efficiently.
I have read the section of the TikZ manual related to this, but I still don't understand it...
\fill
with\draw
, then the resulting line is exactly equivalent to the boundary of the region to be filled.