如何提高图表的可读性?

如何提高图表的可读性?

我经常需要解释当平均值为 1,2,3 $\sigma$ 时某个方差会发生什么。

这是 MWE。我正在寻找对 x 轴上节点的改进,我认为这些节点的可读性不是很好。

在此处输入图片描述

\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}

答案1

我只是放弃了一些axis on top节点并给了它们一些非平凡的东西fill opacity来达到

\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}

在此处输入图片描述

请注意,axis cs:在 pgfplots 版本1.11或更高版本中是不必要的,但我保留了它们。因此,如果您想将其嵌入到更大的文档中,请考虑遵循 frougon 的建议并将定义设为本地。

\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}

相关内容