2

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?

enter image description here

4
  • 3
    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). – Jasper Habicht Feb 23 at 12:12
  • 1
    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. – SebGlav Feb 23 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! – thisismetrying Feb 23 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! – thisismetrying Feb 23 at 13:49
4

With approximation of your function by controls macro:

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}                   %   had to be instead tikz
\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}
1
  • Exactly. Thank you very much for your thorough answer! – thisismetrying Feb 23 at 13:50
2

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}

Area under curve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.