此问题在此处已有答案:
Fill between standard deviations on Matplotlib lineplot(1个答案)
Filling range of graph in matplotlib(2个答案)
How to use custom error bar in seaborn lineplot(2个答案)
Is there a way to plot 2x Standard Deviation in Seaborn?(2个答案)
21天前关闭
我试图创建一个图,也应该显示标准差。这是我的数据
y20_6 = np.array([18351.6,17976.6,16101.6])
y20_12 = np.array([15664.1,16984.4,18304.7])
y20_18 = np.array([13031.3,13218.8,15468.8])
y80_6 = np.array([17109.4,16890.65,16671.9])
y80_12 = np.array([15867.2,18265.6,16132.8])
y80_18 = np.array([18304.2,17070.3,15539.1])
i20_6 = np.array([11375,11070.3,10398.4])
i20_12 = np.array([11273.4,10929.7,11304.7])
i20_18 = np.array([11789.1,10507.8,12507.8])
i80_6 = np.array([11906.3,9421.88,10218.8])
i80_12 = np.array([9750,10335.95,10921.9])
i80_18 = np.array([10109.4,10660.15,11210.9])
字符串
我取了每组的平均值,用下面的代码创建了图
x = np.array([0,1,2])
y20 = [sum(sub_list) / len(sub_list) for sub_list in np.array([y20_6, y20_12, y20_18])]
y80 = [sum(sub_list) / len(sub_list) for sub_list in np.array([y80_6, y80_12, y80_18])]
i20 = [sum(sub_list) / len(sub_list) for sub_list in np.array([i20_6, i20_12, i20_18])]
i80 = [sum(sub_list) / len(sub_list) for sub_list in np.array([i80_6, i80_12, i80_18])]
z = np.array([10518.2, 10518.2, 10518.2])
my_xticks = ['6 hrs','12 hrs','18 hrs']
plt.xticks(x, my_xticks)
plt.plot(x, y20, linestyle='-', marker='o', label='20 $^\circ$C, 175 $^\circ$C')
plt.plot(x, y80, linestyle='-', marker='v',label='80 $^\circ$C, 175 $^\circ$C')
plt.plot(x, i20, linestyle='-', marker='s',label='20 $^\circ$C, 275 $^\circ$C')
plt.plot(x, i80, linestyle='-', marker='x',color='black', label='80 $^\circ$C, 275 $^\circ$C')
plt.plot(x, z,linestyle='--', label='Referrence')
plt.legend(bbox_to_anchor=(1.35, 1.005), loc='upper right', borderaxespad=0)
plt.ylim([10000, 18000])
#plt.show()
plt.savefig('AL380', dpi=600, bbox_inches='tight')
型
示例图如下所示。我想创建一个类似的。
的数据
但是,我不能在图中添加标准差线条。有人能帮助我吗?
2条答案
按热度按时间cnh2zyt31#
一种解决方案是使用
plt.fill_between
:字符串
您只需要计算每个数据点的平均值和标准值。
qlzsbp2j2#
按照注解中的建议使用
seaborn.lineplot
:范例:
字符串
输出量:
的数据