\documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{arrows.meta, intersections, backgrounds, shapes.geometric, positioning, arrows.meta, positioning, tikzmark, patterns} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{fillbetween} \begin{document} \pgfmathdeclarefunction{poly}{0}{% \pgfmathparse{-x^3+5*(x^2)-3*x-3}% } \begin{tikzpicture}[xscale=1.5,yscale=.5] \begin{axis}[ xmin=-2, xmax=5, ymin=-5, ymax=10, axis y line=left, axis x line=bottom, xtick={-1.2,2,4.2}, xticklabels={$a$,$c$,$b$}, ytick={3}, yticklabels={$\mu=f(c)$}, samples=160 ] \addplot[name path=poly,black,thick,mark=none,domain=-1.2:4.2,stack plots=y,color=black,very thick] {poly} node[right] {$\mathcal{C}_f$}; \addplot[name path=line,gray,no markers,line width=1pt,domain=-1.2:4.2,color=red] {3}; \addplot fill between[ of = poly and line, split, % calculate segments every even segment/.style = {pattern=north east lines, pattern color=lightgray}, every odd segment/.style ={pattern=north east lines, pattern color=lightgray} ]; \draw[help lines] (axis cs:-1.2,-5) -- (axis cs:-1.2,3); \draw[help lines] (axis cs:2,-5) -- (axis cs:2,3); \draw[help lines] (axis cs:4.2,-5) -- (axis cs:4.2,3); \draw[help lines] (-2,3) -- (-1.2,3); \end{axis} \end{tikzpicture} \end{document}