在气泡图中包含标准偏差

在气泡图中包含标准偏差

我想绘制一个数据集,其中一个值(Q)取决于两个参数(KpKi)。下面给出了数据集和相应气泡图的示例。

但是,我还想将标准差可视化Qstd。我该如何整合这些信息,使其易于理解且具有视觉吸引力?

我想到的是模糊气泡或为Qstd每个气泡绘制额外的彩色环。如何使用来实现pgfplots

我也愿意接受有关可视化该数据集的其他想法。

示例无Qstd

\documentclass[10pt,a4paper,parskip,serif]{article}
\usepackage{tikz,pgfplots}
\usepackage[active,tightpage]{preview}
\pagestyle{empty}
\PreviewEnvironment{tikzpicture}

\begin{filecontents}{data.csv}
Kp,Ki,Q,Qstd
0.0,0.0,30.1844312897,0.54402489898
0.0,0.5,22.789281251,2.23476270379
0.0,1.0,23.6969167397,2.99701784658
0.0,1.5,23.4746028477,5.87823322698
0.5,0.0,25.32901901,0.150010893549
0.5,0.5,19.4956749082,1.46863839933
0.5,1.0,23.9601961928,3.01916075502
0.5,1.5,27.1885578424,4.8198873641
1.0,0.0,19.0979455638,0.117109263912
1.0,0.5,22.9133161064,2.02426507174
1.0,1.0,23.4744457188,6.00164550252
1.0,1.5,26.0198672873,5.45956114632
1.5,0.0,13.5827222174,1.93959858517
1.5,0.5,28.2232094687,15.8364541786
1.5,1.0,26.1093208489,0.635137680728
1.5,1.5,26.7062696696,2.72319357128
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}
    \addplot[only marks, scatter, scatter src=0,
            visualization depends on={\thisrow{Q}*0.3 \as \perpointmarksize},
            scatter/use mapped color={draw=black,fill=black},
            scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize}
        ] table [x=Kp,y=Ki, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}

\end{document}

气泡图

答案1

虽然没有详细阅读你的文字,但我也想到了画戒指的想法。

有关其工作原理的详细信息,请查看代码中的注释。

% used PGFPlots v1.14
\begin{filecontents}{data.csv}
Kp,Ki,Q,Qstd
0.0,0.0,30.1844312897,0.54402489898
0.0,0.5,22.789281251,2.23476270379
0.0,1.0,23.6969167397,2.99701784658
0.0,1.5,23.4746028477,5.87823322698
0.5,0.0,25.32901901,0.150010893549
0.5,0.5,19.4956749082,1.46863839933
0.5,1.0,23.9601961928,3.01916075502
0.5,1.5,27.1885578424,4.8198873641
1.0,0.0,19.0979455638,0.117109263912
1.0,0.5,22.9133161064,2.02426507174
1.0,1.0,23.4744457188,6.00164550252
1.0,1.5,26.0198672873,5.45956114632
1.5,0.0,13.5827222174,1.93959858517
1.5,0.5,28.2232094687,15.8364541786
1.5,1.0,26.1093208489,0.635137680728
1.5,1.5,26.7062696696,2.72319357128
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        % moved all options that are in common here
        only marks,
        scatter, scatter src=0,
        table/.cd,
            x=Kp,
            y=Ki,
            col sep=comma,
    ]
        % outer ring
        \addplot [
            % determine size of ring + Qstd
            visualization depends on={
                (\thisrow{Q}+\thisrow{Qstd})*0.3 \as \perpointmarksize
            },
            scatter/use mapped color={
                % don't "draw" ...
                % (unfortunately `draw=none' doesn't seem to work)
                draw opacity=0,
                % ...  and fill it
                fill=black!25,
            },
            scatter/@pre marker code/.append style={
                /tikz/mark size=\perpointmarksize,
            },
        ] table {data.csv};

        % inner ring
        \addplot [
            % determine size of ring - Qstd
            visualization depends on={
                (\thisrow{Q}-\thisrow{Qstd})*0.3 \as \perpointmarksize
            },
            scatter/use mapped color={
                % here we also don't want to "draw" ...
                draw opacity=0,
                % ... but fill the part that is *not* part of the value
                % including the Qstd
                fill=white,
            },
            scatter/@pre marker code/.append style={
                /tikz/mark size=\perpointmarksize,
            },
        ] table {data.csv};

        % "mean" ring
        \addplot [
            % determine size of ring
            visualization depends on={
                \thisrow{Q}*0.3 \as \perpointmarksize
            },
            scatter/use mapped color={
                % this time we only want to "draw" ...
                draw=black,
                % but not to fill
                fill opacity=0,
            },
            scatter/@pre marker code/.append style={
                /tikz/mark size=\perpointmarksize,
            },
        ] table {data.csv};
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

答案2

这是一个不同的方法(使用元帖子luamplib) 强调正态分布以及每个点与平均值和标准差的偏差。

在此处输入图片描述

在 MP 中,您必须“手动”做更多事情,但好处是您可以准确绘制您想要的内容。我使用 计算了您的数据中的均值 ( mm) 和平均标准差 ( ) 。msdmean of SD = sqrt(mean of variance)

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{fontspec}\setmainfont{Corbel}
\begin{document}
\mplibtextextlabel{enable}
\mplibnumbersystem{decimal}

\begin{mplibcode}
beginfig(1);

    vardef round(expr x) = floor(x*10+1/2)/10 enddef;

    vardef exp(expr x) = mexp(256x) enddef; % hide MP's version of exp

    vardef normal_pdf(expr x) = 
        exp(-1/2x*x)/2.50662827463  % \sqrt(2\pi) \simeq 2.50663 
    enddef;

    path mean_pdf_curve;
    numeric s, r; r=3; s=1/64;
    mean_pdf_curve = ((-r,normal_pdf(-r)) for t=s-r step s until r: -- (t,normal_pdf(t)) endfor)
                     xscaled 4mm yscaled 20mm;

    numeric mm, msd;
    mm = 23.89036106015;
    msd = 5.09696198847413;

    vardef markit(expr x,y, mean, sd) =
        draw mean_pdf_curve shifted (x*u,y*v) withcolor 3/4 white;
        draw mean_pdf_curve 
             xscaled sqrt(sd/msd)
             yscaled (3/4+1/4sqrt(msd/sd))
             shifted (mean-mm,0)
             shifted (x*u,y*v) withcolor 2/3 red;
        label(decimal round(mean), (x*u+mean-mm,y*v)) withcolor 2/3 red;
    enddef;

    u = 6cm; v = 5cm;
    markit(0.0,0.0,30.1844312897,0.54402489898);
    markit(0.0,0.5,22.789281251, 2.23476270379);
    markit(0.0,1.0,23.6969167397,2.99701784658);
    markit(0.0,1.5,23.4746028477,5.87823322698);
    markit(0.5,0.0,25.32901901,0.150010893549);
    markit(0.5,0.5,19.4956749082,1.46863839933);
    markit(0.5,1.0,23.9601961928,3.01916075502);
    markit(0.5,1.5,27.1885578424,4.8198873641);
    markit(1.0,0.0,19.0979455638,0.117109263912);
    markit(1.0,0.5,22.9133161064,2.02426507174);
    markit(1.0,1.0,23.4744457188,6.00164550252);
    markit(1.0,1.5,26.0198672873,5.45956114632);
    markit(1.5,0.0,13.5827222174,1.93959858517);
    markit(1.5,0.5,28.2232094687,15.8364541786);
    markit(1.5,1.0,26.1093208489,0.635137680728);
    markit(1.5,1.5,26.7062696696,2.72319357128);

    for t=0 step 1/2 until 3/2:
        label(decimal t, (t*u,-1/4v));
        label(decimal t, (-1/3u,t*v));
    endfor

endfig;
\end{mplibcode}
\end{document}

相关内容