# How to plot the following graph using TikZ?

I am trying to plot the curve and the shaded area shown in the screenshot below. I do not have the expression for the curve, but I was thinking about maybe using some kind of interpolating curve to get the right shape. However, I am quite new to the TikZ-package and I am not sure how I would start in order to achieve this. Also, how can the shaded area be drawn? • You already posted a question here on TeX.SX where you showed that you have at least basic knowledge of TikZ. =) So, I would suggest that you provide some code as a starting point. We will be happy to help you where you got stuck. To help you get started: you may want to use \draw plot[smooth] coordinates {<coordinate1> <coordinate2> <coordinate3> ...} to draw the curve (also see: tex.stackexchange.com/q/33607/47927). Feb 23, 2021 at 12:12
• Here I strongly recommand to use Bezier curve. A little bit of search here will help you start. I think that you only need five points, here (two extremities and three summits) with null slope tangents. Pretty straightforward. Come here with your first try and we'll give help if needed. Feb 23, 2021 at 12:30
• @JasperHabicht Yes, I have some very basic knowledge of the package. However, I was a bit stuck since I didn't have the function of the curve and would only be able to draw the axes. Your starting tips was what I was looking for. Thank you! Feb 23, 2021 at 13:47
• @SebGlav I was also think about using a Bezier curve. However, I did not know the command for this in TikZ. Anyways, thank you for your advice! Feb 23, 2021 at 13:49

With approximation of your function by controls macro: \documentclass[margin=3mm]{standalone}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta,
patterns,
pgfplots.fillbetween}   %   <---

\begin{document}
\begin{tikzpicture}[>=Straight Barb,
every pin edge/.append style={Circle-, color=black, semithick}
]
% function
\path[name path=A]  (-3,0) -- (3,0);
\draw[thick,
name path=B]  (-3,0.1) .. controls +(1.0,0) and +(-0.3,0) .. (-1,1.5)
.. controls +(0.3,0) and +(-0.3,0) .. ( 0,1.0)
.. controls +(0.3,0) and +(-0.3,0) .. ( 1,1.5)
.. controls +(0.3,0) and +(-1.0,0) .. ( 3,0.1);
\tikzfillbetween[of=A and B] {fill=cyan!30};
\coordinate[pin=75:{Area $E[x^2]$}] (aux) at (1.5,0.5);
% axis
\draw[->] (-3.5,0) -- (3.5,0) node[below left] {$\omega$};
\draw[->] (0,-0.1) node[below] {0} -- (0,3) node[below right] {$S_{xx}(\omega)$};
\end{tikzpicture}

\begin{tikzpicture}[>=Straight Barb,
every pin edge/.append style={Circle-, color=black, semithick}
]
% function
\path[name path=A]  (-3,0) -- (3,0);
\draw[thick,
name path=B]  (-3,0.1) .. controls +(1.0,0) and +(-0.3,0) .. (-1,1.5)
.. controls +(0.3,0) and +(-0.3,0) .. ( 0,1.0)
.. controls +(0.3,0) and +(-0.3,0) .. ( 1,1.5)
.. controls +(0.3,0) and +(-1.0,0) .. ( 3,0.1);
\tikzfillbetween[of=A and B] {pattern color=gray,
pattern=north east lines};
\coordinate[pin=75:{Area $E[x^2]$}] (aux) at (1.5,0.5);
% axis
\draw[->] (-3.5,0) -- (3.5,0) node[below left] {$\omega$};
\draw[->] (0,-0.1) node[below] {0} -- (0,3) node[below right] {$S_{xx}(\omega)$};
\end{tikzpicture}
\end{document}

• Exactly. Thank you very much for your thorough answer! Feb 23, 2021 at 13:50

I came with this, with a similar approach but without any fancy package.

\documentclass[tikz,border=3.14159mm]{standalone}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}[line width=.75pt]
\def\xa{5.5} \def\ya{.2}
\def\xb{1.8} \def\yb{2}
\def\xc{0} \def\yc{1.3}
\def\tang{.7}

\def\curve{
(-\xa,\ya) .. controls ++ (1.5,0) and ++ (-1.5*\tang,0) ..
(-\xb,\yb) .. controls ++ (\tang,0) and ++ (-\tang,0) ..
(-\xc,\yc) .. controls ++ (\tang,0) and ++ (-\tang,0) ..
(\xb,\yb) .. controls ++ (1.5*\tang,0) and ++ (-1.5,0) ..
(\xa,\ya)
}

\draw [-stealth] (-\xa-1,0) -- (\xa+1,0) node[below left] {$\omega$};
\draw [-stealth] (0,0) node[below] {$0$} -- (0,3)  node[below right] {$S_x(\omega)$};

\path[pattern=north west lines, pattern color=orange] (-\xa,0) -- \curve -- (\xa,0) -- cycle;
\draw  \curve;

\draw (\xb+.5,\yc) --++ (1,1) node [inner sep=1pt,right] {Area $E[x^2]$};

\end{tikzpicture}
\end{document} 