gpt4 book ai didi

python - 基于置信区间值的误差带等高线图

转载 作者:太空宇宙 更新时间:2023-11-03 20:35:07 25 4
gpt4 key购买 nike

我想要一个等值线图,其中不同的色带代表线图的不同置信区间。考虑下面来自 this page 的代码:

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)

结果是:

                             Fig.1 - image courtesy of pydata.org.                

now if I'm not mistaken those error bands represent a confidence band (e.g. 95%). What I want is to have different confidence intervals (e.g. given a list like [50, 60, 70, 80, 90]) represented as a contour plot around the centerline.

P.S.1. It doesn't have to be seaborn or even matplotlib for that matter. Even non-Python solutions are also ok for me as far as it is Free, Libre and Open Source Software (FLOSS).

P.S.2. I think the solution should include the ci parameter of the lineplot function. Maybe I can have a for loop going over the list above and plot different confidence intervals on top of each other?

P.S.3. So far I have realized that putting the last line of the above code inside a for loop over the mentioned list of confidence intervals would plot them on top of each other:

for ii in [10, 50, 90]:
ax = sns.lineplot(x="timepoint", y="signal", data=fmri, ci=ii)
                             Fig.2 - putting the plotting command in a for loop.                

但是,我不知道如何控制这些透明带的色调/颜色图,也不知道如何根据这些值添加图例。

最佳答案

我想我已经找到了我要找的东西:

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
fmri = sns.load_dataset("fmri")

confidenceIntervals = [10, 30, 50, 70, 90]

colorPalette = sns.color_palette("ch:2.5,-.2,dark=.4", n_colors=len(confidenceIntervals))[::-1]

for jj, ii in enumerate(confidenceIntervals):
ax = sns.lineplot(x="timepoint", y="signal", data=fmri, ci=ii, label=str(ii),
color=colorPalette[jj])

ax.legend(fancybox=True, framealpha=1, shadow=True, borderpad=1)

结果是:

                            Fig.3 - final results with the Seaborn color palette and legend.                

可以找到更多颜色选项 here 。基本上,sns.lineplot 函数有一个 kwargs 参数,根据文档:

passes down arguments to plt.plot at draw time

关于python - 基于置信区间值的误差带等高线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57217275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com