Truncated at the top of the graph for a Lorentzian function

As samcarter has already shown in her answer the key is to increase samples. But instead of increasing it to 10000 I suggest to increase it only to 1001 and also use the smooth key, which gives almost the same result and also works for PDFLaTeX (and not only with LuaLaTeX. Otherwise one has to increase TeX's "memory").

Using only smooth with 101 samples still shows a spike, as now can be seen in Ruixi Zhang's answer.

Ruixi and I use an uneven number of samples, because this ensures that there is also a sample point "in the middle" of the domain, i.e. in this case with a domain of -4 to 4 at 0, where we find the maximum value of the given function.

(Please note that I also heavily simplified your code. For example you need only one \addplot command to achieve what you want.)

Edit

An even better approach is to reformulate the function using non-linear spacing as Max has shown in his answer. Here I edited his code so that it also works for \xz <> 0 and also allows to have unsymmetrical lower and upper bounds of the domain (lb and ub instead of just b).

The non-linear spacing approach is always a good idea if you otherwise need to increase the samples to a "high" value because there is a rather quick change in the slope/steepness of the function (as in your case -- or the other cases that link to each other that are stated in comments of my codes).

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        patterns,
        spy,
    }
    \tikzset{
        hatch distance/.store in=\hatchdistance,
        hatch distance=10pt,
        hatch thickness/.store in=\hatchthickness,
        hatch thickness=2pt,
    }

    \makeatletter
    \pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
    {\pgfqpoint{0pt}{0pt}}
    {\pgfqpoint{\hatchdistance}{\hatchdistance}}
    {\pgfpoint{\hatchdistance-2pt}{\hatchdistance-2pt}}%
    {
        \pgfsetcolor{\tikz@pattern@color}
        \pgfsetlinewidth{\hatchthickness}
        \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
        \pgfusepath{stroke}
    }
    \makeatother
\begin{document}
\begin{tikzpicture}[
    % -------------------------------------------------------------------------
    % declare functions
    declare function={
        % Lorentzian function
        L(\x,\xz,\ep) = (1/pi) * (\ep/((\x-\xz)^2 + (\ep)^2));
        % state lower and upper boundaries
        lb = -4;
        ub = 4;
        % -----------------------------------------------------------------
        %%% non-linear spacing:
        %%% adapted from <https://tex.stackexchange.com/a/443731/95441>
        % "non-linearity factor"
        a = 1;
        % function to use for the nonlinear spacing
        Y(\x,\a) = exp(\a*\x);
        % rescale to former limits (domain=lb:ub) taking into account `\xz',
        % where sample points should be densest
        X(\x,\a,\xz) =
            + (\x >= \xz) * ( (Y(\x,\a)  - Y(\xz,\a))/(Y(ub,\a)   - Y(\xz,\a)) * (ub - \xz) + \xz )
            + (\x < \xz)  * ( (Y(\x,-\a) - Y(lb,-\a))/(Y(\xz,-\a) - Y(lb,-\a)) * (\xz - lb) + lb )
        ;
        % -----------------------------------------------------------------
        % create simplified functions when `xz' and `ep' are known/fix
        xz = 0;
        ep = 0.1;
        myL(\x) = L(\x,xz,ep);
        myX(\x) = X(\x,a,xz);
    },
    % -------------------------------------------------------------------------
    % (only needed for the spy stuff)
    spy using outlines={
        circle,
        magnification=10,
        size=20mm,
        connect spies,
    },
    % -------------------------------------------------------------------------
]
    \begin{axis}[
        xmin=lb,
        xmax=ub,
        ymin=0,
        ymax=3.5,       % <-- (adapted)
        axis on top,
        % (moved common options here)
        domain=lb:ub,
        % -----------------------------
        % using non-linear spacing `samples' can drastically be reduced
        samples=51,
        % added `smooth'
        smooth,
        % -----------------------------
    ]

%        % old solution using linear spacing
%        \addplot [
%            color=gray,
%            pattern=flexible hatch,
%            pattern color=orange,
%            % -----------------------------
%            % increased `samples'
%            samples=1001,
%            % -----------------------------
%        % (simplified and corrected unbalanced braces)
%        ] {(1/pi) * 0.1/(x^2+0.01)};

        % new solution using non-linear spacing
        \addplot [
            color=gray,
            pattern=flexible hatch,
            pattern color=orange,
        ] ({myX(x)},{myL(myX(x))});

        % -----------------------------------------------------------------
        % (for debugging purposes only
        %  it shows the points where the main function is evaluated)
        \addplot [
            only marks,
            mark size=0.5pt,
            blue,
        ] ({myX(x)},3.25);
        % ---------------------------------------------------------------------
        % (only needed for the spy stuff)
            \coordinate (spy) at (axis cs:-2.25,2.5);
            \coordinate (A)   at (axis cs:0,3.15);
        \spy on (A) in node at (spy);
        % ---------------------------------------------------------------------

    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code


You need a higher sampling rate:

\documentclass{article}
    \usepackage{tikz,amsmath,xcolor}
    \usetikzlibrary{patterns}
    \usepackage{pgfplots}
    \usetikzlibrary{spy}
    \begin{document}
    \begin{tikzpicture}[spy using outlines={circle=.5cm, magnification=3, size=.5cm, connect spies}]
    \tikzset{
        hatch distance/.store in=\hatchdistance,
        hatch distance=10pt,
        hatch thickness/.store in=\hatchthickness,
        hatch thickness=2pt
    }

    \makeatletter
    \pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
    {\pgfqpoint{0pt}{0pt}}
    {\pgfqpoint{\hatchdistance}{\hatchdistance}}
    {\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
    {
        \pgfsetcolor{\tikz@pattern@color}
        \pgfsetlinewidth{\hatchthickness}
        \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
        \pgfusepath{stroke}
    }
    \makeatother

    \begin{axis}[
        xmin=-4,xmax=4,
        xlabel={},
%        ymin=0,ymax=3,
        axis on top,
        legend style={legend cell align=right,legend plot pos=right}] 
       %\begin{scope}
    %\spy[green!70!black,size=2cm] on (2.5,1) in node [fill=white] at (8,2);
       %\end{scope}
    \addplot[color=gray,domain=-4:4,samples=100] {(1/pi)*(0.1/((x)^2+0.01)};

       \addplot+[color=gray,mark=none,
        domain=-4:4,
        samples=100,
        pattern=flexible hatch,
        area legend,
        samples=10000,
        pattern color=orange]{(1/pi)*(0.1/((x)^2+0.01)} \closedcycle;


    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here


The idea is to use an odd number of sample points and use smooth. Note: Too many sample points tends to exhaust computer memory, so I used samples=101 for the curve and samples=101 for the orange shading.

\documentclass{article}
    \usepackage{tikz,amsmath,xcolor}
    \usetikzlibrary{patterns}
    \usepackage{pgfplots}
    \usetikzlibrary{spy}
    \begin{document}
    \begin{tikzpicture}[spy using outlines={circle=.5cm, magnification=3, size=.5cm, connect spies}]
    \tikzset{
        hatch distance/.store in=\hatchdistance,
        hatch distance=10pt,
        hatch thickness/.store in=\hatchthickness,
        hatch thickness=2pt
    }

    \makeatletter
    \pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
    {\pgfqpoint{0pt}{0pt}}
    {\pgfqpoint{\hatchdistance}{\hatchdistance}}
    {\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
    {
        \pgfsetcolor{\tikz@pattern@color}
        \pgfsetlinewidth{\hatchthickness}
        \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
        \pgfusepath{stroke}
    }
    \makeatother

    \begin{axis}[
        xmin=-4,xmax=4,
        xlabel={},
%        ymin=0,ymax=3,
        axis on top,
        legend style={legend cell align=right,legend plot pos=right}] 
       %\begin{scope}
    %\spy[green!70!black,size=2cm] on (2.5,1) in node [fill=white] at (8,2);
       %\end{scope}
    \addplot[color=gray,domain=-4:4,samples=101,smooth] {(1/pi)*(0.1/((x)^2+0.01)};

       \addplot+[color=gray,mark=none,
        domain=-4:4,
        samples=101,
        pattern=flexible hatch,
        area legend,
        pattern color=orange]{(1/pi)*(0.1/((x)^2+0.01)} \closedcycle;


    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here