با استفاده از بسته pgfplots
میتوان نمودار مورد نظر را ترسیم نمود.
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xepersian}
\settextfont{Yas}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
xtick=\empty,
xmin=0, xmax=8,
ymin=0, ymax=1.6,
extra x ticks={2,3,5,7},
extra x tick labels={$a$,$b$,$c$,$d$},
axis y line=left,
xlabel={$x$},
ylabel={$y$},
every axis x label/.style={at={(ticklabel* cs:1)}, anchor=west},
every axis y label/.style={at={(ticklabel* cs:1)}, anchor=south},
ytick={1},
legend entries={$f(x)$,$h(x)$},
legend style={draw=none},
]
\addplot[thick,domain=2:7,samples=500]{(x<3)*(-2+x)+and(!(x<3),x<5)*(+1)+!(x<5)*(-x/2+7/2)};
\addplot[thick,domain=2.49:6.01,samples=500,red,densely dotted]{and(!(x<2.5),x<6)*(+1)};
\draw [help lines] (axis cs:3,0) -- (axis cs:3,1);
\draw [help lines] (axis cs:5,0) -- (axis cs:5,1);
\draw [help lines,blue] (axis cs:4,0.3) node [below] {$O$} -- (axis cs:6,0.3) node [above, near start] {$\ell$};
\end{axis}
\end{tikzpicture}
\end{document}
نتیجه: