1

I often have to explain what happens for a certain variance at 1,2,3 $\sigma$ of the average.

This is MWE. I am looking for improvments on the nodes along the x axis which I believe are not very readible.

enter image description here

\documentclass[border =2mm]{standalone}
\usepackage[]{graphicx}
\usepackage[]{color}

%Paramètres
\def\KK{40} \def\VolY{0.20} \def\Kmin{20}   \def\Ktick{40}  \def\Kmax{60}

\begin{document}

%Boundaries
\def\TTOne{1}%
\pgfmathsetmacro{\RacineTT}{sqrt(\TTOne)}%
\pgfmathsetmacro{\VolTwo}{\RacineTT*\VolY}%
\pgfmathsetmacro{\TTwo}{\RacineTT*\VolY}%

\pgfmathsetmacro{\VolInKK}{sqrt(\TTOne)*\VolY*\KK}%
\pgfmathtruncatemacro{\KmThreeS}{round(\KK-3*\VolInKK)}%
\pgfmathtruncatemacro{\KmTwoS}{round(\KK-2*\VolInKK)}%
\pgfmathtruncatemacro{\KmOneS}{round(\KK-1*\VolInKK)}%
\pgfmathtruncatemacro{\KpOneS}{round(\KK+1*\VolInKK)}%
\pgfmathtruncatemacro{\KpTwoS}{round(\KK+2*\VolInKK)}%
\pgfmathtruncatemacro{\KpThreeS}{round(\KK+3*\VolInKK)}%

\tikzset{strike/.style={circle, scale=0.6, fill=white,draw=blue,opacity=1,draw=blue!50}}

\pgfplotsset{
/pgf/declare function={
    GEuler(\x,\mean,\std) = 1/(\std*sqrt(2*pi))*exp(-((\x-\mean)^2)/(2*\std^2));
    %   MyGauss(\x) = GEuler(\x,44,4);
    },
}

\pgfplotsset{
  set layers,% using layers
  mark layer=axis tick labels% defines the layer of the marks
}

\begin{tikzpicture}

\begin{axis}[
        domain={\KK-3.5*\VolInKK}:{\KK+3.5*\VolInKK},
        height=5cm,width=12cm, no markers,
        samples=101, axis lines*=left,
        every axis y label/.style={at=(current axis.above origin),anchor=south,},
        every axis x label/.style={at=(current axis.right of origin),anchor=west,
        },
        y axis line style={draw opacity=0},
        xtick={\KK},
        xticklabels={$F=$ \textbf{\KK}},
        ytick=\empty,
        tick align=outside,
        major tick length=2mm,
        typeset ticklabels with strut,
    enlargelimits=false,clip=false,axis on top,
    clip mode=individual]



    % filled areas at the sides
    \addplot [fill=red!20,draw=none,domain=\KmThreeS:\KpThreeS] {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!30,draw=none,domain=\KmTwoS:\KpTwoS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!50,draw=none,domain=\KmOneS:\KpOneS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [very thick,cyan!50!black,samples=201]             {GEuler(\x,\KK,\VolInKK)};


    \node at (axis cs:\KK,0) [strike,fill=red,draw=red]     {\KK};      
    \node at (axis cs:\KmThreeS,0) [strike]     {\KmThreeS};        
    \node at (axis cs:\KmTwoS,0) [strike]       {\KmTwoS};      
    \node at (axis cs:\KmOneS,0) [strike]       {\KmOneS};      
    \node at (axis cs:\KpOneS,0) [strike]       {\KpOneS};      
    \node at (axis cs:\KpTwoS,0) [strike]       {\KpTwoS};      
    \node at (axis cs:\KpThreeS,0) [strike]     {\KpThreeS};        


\end{axis}
\end{tikzpicture}
\end{document}
3
  • I'm afraid your code doesn't compile, please fix this.
    – frougon
    Mar 7, 2020 at 17:09
  • I forgot the tikz librairies ! I edit.
    – JeT
    Mar 7, 2020 at 17:10
  • Something else too...
    – frougon
    Mar 7, 2020 at 17:11

1 Answer 1

2

I only dropped axis on top and gave the nodes some nontrivial fill opacity to arrive at

\documentclass[tikz,border =2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

%Paramètres
\def\KK{40} \def\VolY{0.20} \def\Kmin{20}   \def\Ktick{40}  \def\Kmax{60}

\begin{document}

%Boundaries
\def\TTOne{1}%
\pgfmathsetmacro{\RacineTT}{sqrt(\TTOne)}%
\pgfmathsetmacro{\VolTwo}{\RacineTT*\VolY}%
\pgfmathsetmacro{\TTwo}{\RacineTT*\VolY}%

\pgfmathsetmacro{\VolInKK}{sqrt(\TTOne)*\VolY*\KK}%
\pgfmathtruncatemacro{\KmThreeS}{round(\KK-3*\VolInKK)}%
\pgfmathtruncatemacro{\KmTwoS}{round(\KK-2*\VolInKK)}%
\pgfmathtruncatemacro{\KmOneS}{round(\KK-1*\VolInKK)}%
\pgfmathtruncatemacro{\KpOneS}{round(\KK+1*\VolInKK)}%
\pgfmathtruncatemacro{\KpTwoS}{round(\KK+2*\VolInKK)}%
\pgfmathtruncatemacro{\KpThreeS}{round(\KK+3*\VolInKK)}%

\tikzset{strike/.style={circle, scale=0.6, 
fill=white,fill opacity=0.8,text opacity=1,draw=blue!50}}

\pgfplotsset{
/pgf/declare function={
    GEuler(\x,\mean,\std) = 1/(\std*sqrt(2*pi))*exp(-((\x-\mean)^2)/(2*\std^2));
    %   MyGauss(\x) = GEuler(\x,44,4);
    },
}

\pgfplotsset{
  set layers,% using layers
  mark layer=axis tick labels% defines the layer of the marks
}

\begin{tikzpicture}

\begin{axis}[
        domain={\KK-3.5*\VolInKK}:{\KK+3.5*\VolInKK},
        height=5cm,width=12cm, no markers,
        samples=101, axis lines*=left,
        every axis y label/.style={at=(current axis.above origin),anchor=south,},
        every axis x label/.style={at=(current axis.right of origin),anchor=west,
        },
        y axis line style={draw opacity=0},
        xtick={\KK},
        xticklabels={$F=\mathbf{\KK}$},
        ytick=\empty,
        tick align=outside,
        major tick length=2mm,
        typeset ticklabels with strut,
        ymax={GEuler(\KK,\KK,\VolInKK)+0.001},
    enlargelimits=false,%clip=false,axis on top,
    clip mode=individual]



    % filled areas at the sides
    \addplot [fill=red!20,draw=none,domain=\KmThreeS:\KpThreeS] {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!30,draw=none,domain=\KmTwoS:\KpTwoS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!50,draw=none,domain=\KmOneS:\KpOneS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [very thick,cyan!50!black,samples=201]             {GEuler(\x,\KK,\VolInKK)};


    \node at (axis cs:\KK,0) [strike,fill=red,draw=red]     {\KK};      
    \node at (axis cs:\KmThreeS,0) [strike]     {\KmThreeS};        
    \node at (axis cs:\KmTwoS,0) [strike]       {\KmTwoS};      
    \node at (axis cs:\KmOneS,0) [strike]       {\KmOneS};      
    \node at (axis cs:\KpOneS,0) [strike]       {\KpOneS};      
    \node at (axis cs:\KpTwoS,0) [strike]       {\KpTwoS};      
    \node at (axis cs:\KpThreeS,0) [strike]     {\KpThreeS};        
\end{axis}


\end{tikzpicture}
\end{document}

enter image description here

Note that the axis cs: are unnecessary in pgfplots versions 1.11 or later, but I kept them. So if you want to embed this in a larger document, please consider following frougon's suggestion and make the definitions local.

\documentclass[tikz,border =2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}[declare function={
    GEuler(\x,\mean,\std)=1/(\std*sqrt(2*pi))*exp(-((\x-\mean)^2)/(2*\std^2));}]

\def\KK{40} \def\VolY{0.20} \def\Kmin{20}   \def\Ktick{40}  \def\Kmax{60}

%Boundaries
\def\TTOne{1}%
\pgfmathsetmacro{\RacineTT}{sqrt(\TTOne)}%
\pgfmathsetmacro{\VolTwo}{\RacineTT*\VolY}%
\pgfmathsetmacro{\TTwo}{\RacineTT*\VolY}%

\pgfmathsetmacro{\VolInKK}{sqrt(\TTOne)*\VolY*\KK}%
\pgfmathtruncatemacro{\KmThreeS}{round(\KK-3*\VolInKK)}%
\pgfmathtruncatemacro{\KmTwoS}{round(\KK-2*\VolInKK)}%
\pgfmathtruncatemacro{\KmOneS}{round(\KK-1*\VolInKK)}%
\pgfmathtruncatemacro{\KpOneS}{round(\KK+1*\VolInKK)}%
\pgfmathtruncatemacro{\KpTwoS}{round(\KK+2*\VolInKK)}%
\pgfmathtruncatemacro{\KpThreeS}{round(\KK+3*\VolInKK)}%

\begin{axis}[
        set layers,% using layers
        mark layer=axis tick labels,% defines the layer of the marks
        domain={\KK-3.5*\VolInKK}:{\KK+3.5*\VolInKK},
        height=5cm,width=12cm, no markers,
        samples=101, axis lines*=left,
        every axis y label/.style={at=(current axis.above origin),anchor=south,},
        every axis x label/.style={at=(current axis.right of origin),anchor=west,
        },
        y axis line style={draw opacity=0},
        xtick={\KK},
        xticklabels={$F=\mathbf{\KK}$},
        ytick=\empty,
        tick align=outside,
        major tick length=2mm,
        typeset ticklabels with strut,
        ymax={GEuler(\KK,\KK,\VolInKK)+0.001},
    enlargelimits=false,%clip=false,axis on top,
    clip mode=individual]



    % filled areas at the sides
    \addplot [fill=red!20,draw=none,domain=\KmThreeS:\KpThreeS] {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!30,draw=none,domain=\KmTwoS:\KpTwoS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [fill=blue!50,draw=none,domain=\KmOneS:\KpOneS]    {GEuler(\x,\KK,\VolInKK)}   \closedcycle;
    \addplot [very thick,cyan!50!black,samples=201]             {GEuler(\x,\KK,\VolInKK)};

    \begin{scope}[nodes={circle, scale=0.6, 
        fill=white,fill opacity=0.8,text opacity=1,draw=blue!50}]
    \node at (\KK,0) [fill=red,draw=red]     {\KK};      
    \node at (\KmThreeS,0)     {\KmThreeS};        
    \node at (\KmTwoS,0)       {\KmTwoS};      
    \node at (\KmOneS,0)       {\KmOneS};      
    \node at (\KpOneS,0)       {\KpOneS};      
    \node at (\KpTwoS,0)       {\KpTwoS};      
    \node at (\KpThreeS,0)     {\KpThreeS};   
    \end{scope}     
\end{axis}


\end{tikzpicture}
\end{document}
5
  • Thank you @Schrödinger's cat, I also see the top of the curve is cut (must be a clipping problem ?)
    – JeT
    Mar 7, 2020 at 17:17
  • @Julien-ElieTaieb This is already fixed. It is basically a consequence of enlargelimits=false so I added an appropriate ymax.
    – user194703
    Mar 7, 2020 at 17:19
  • Merci @Schrödinger'scat ! That was fast :) One last question, do you see other elements/information that could improve the pedagogic / self explanatory impact of this graph ?
    – JeT
    Mar 7, 2020 at 17:24
  • @Julien-ElieTaieb I cannot answer this because this will depend on the audience and the styles of the other graphical elements.
    – user194703
    Mar 7, 2020 at 17:26
  • Fair enough :) Thank you again.
    – JeT
    Mar 7, 2020 at 17:26

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.