%\documentclass[10pt,a4paper]{article}
\documentclass[border=10]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
    integral segments/.code={\pgfmathsetmacro\integralsegments{#1}},
    integral segments=3,
    integral samples/.code={\edef\integralsamples{#1}},
    integral samples = 10,
    integral min/.style args={#1:#2}{
        ybar interval,
        domain=#1:#2,
        samples=\integralsegments+1,
        x filter/.code={
                               \edef\lastx{\pgfmathresult}
                                \pgfmathresult
                              },%
        y filter/.code={%
                          \pgfmathparse{(#2/(\integralsegments))/\integralsamples}%
                           \edef\tempstep{\pgfmathresult}%
                            \pgfmathparse{f(\lastx)}%
                            \edef\tempa{\pgfmathresult}%
                            \edef\tempb{\pgfmathresult}%
                            \foreach \x in {0,1,...,\integralsamples}%
                               {%
                                \pgfmathparse{f(\lastx+\x*\tempstep)}%
                                 \xdef\tempb{\tempb,\pgfmathresult}%
                                 }%
                               \pgfmathmin{\tempb}{\tempb}
                             },
    },
    integral max/.style args={#1:#2}{
        ybar interval,
        domain=#1:#2,
        samples=\integralsegments+1,
        x filter/.code={
                               \edef\lastx{\pgfmathresult}
                                \pgfmathresult
                              },%
        y filter/.code={%
                          \pgfmathparse{(#2/(\integralsegments))/\integralsamples}%
                           \edef\tempstep{\pgfmathresult}%
                            \pgfmathparse{f(\lastx)}%
                            \edef\tempa{\pgfmathresult}%
                            \edef\tempb{\pgfmathresult}%
                            \foreach \x in {0,1,...,\integralsamples}%
                               {%
                                \pgfmathparse{f(\lastx+\x*\tempstep)}%
                                 \xdef\tempb{\tempb,\pgfmathresult}%
                                 }%
                               \pgfmathmax{\tempb}{\tempb}
                             },
    },   
}
\makeatletter
%see https://tex.stackexchange.com/questions/9722/why-am-i-getting-the-pgf-math-error-unknown-function-getargs
\def\pgfmathmax#1#2{%
%   \pgfmathparse{getargs(#1,#2)}%
     \pgfmathparse{#1,#2}%
    \expandafter\pgfmathmax@\expandafter{\pgfmathresult}%
}
\def\pgfmathmin#1#2{%
    \pgfmathparse{#1,#2}%
    \expandafter\pgfmathmin@\expandafter{\pgfmathresult}%
}
%see https://tex.stackexchange.com/questions/15435/how-do-i-use-pgfmathdeclarefunction-to-create-define-a-new-pgf-function
\makeatother
\begin{document}
\begin{tikzpicture}
\pgfset{declare function={f(\x)=3*exp(-(\x))*(\x)^3+1;}}
\begin{axis}[
    domain=0:8.2,
    xmin=-1, xmax=10.5,
    ymin=-1, ymax=7.5,
    samples=100,
    axis lines=none
]
\addplot [
    blue,
    integral segments=8,
    integral max=0:8,
    fill=blue!20
] {f(x)};
\addplot [
    cyan,
    integral segments=8,
    integral min=0:8,
    fill=red!20
] {f(x)};
\addplot [ultra thick] {f(x)};
\draw[->,thick] (-0.5,0) -- (10,0) coordinate (x axis) node[below] {$x$};
\draw[->,thick] (0,-0.5) -- (0,7) coordinate (y axis) node[left] {$y$};
\end{axis}

\end{tikzpicture}

\end{document}