首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >matplotlib/python -如何绘制这样的图?平均值±3*标准差

matplotlib/python -如何绘制这样的图?平均值±3*标准差
EN

Stack Overflow用户
提问于 2016-07-28 02:41:33
回答 1查看 5K关注 0票数 2

我想要一张这样的照片:

X轴的上下限是给定的,并且比给定的数据大/小得多。

我发现的所有曲线图都只有±1*标准差。

另外,我也不确定如何像这样固定x轴。

我的数据是python的浮点数列表。

现在,我只有三个点,但我希望在它们之间有一条直线,并在这三个点上有垂直线。X轴也不正确。

代码语言:javascript
复制
plt.figure()
x = []
for item in circ_list:
    x.append(float(item))
mean = np.mean(x)
std = np.std(x)
target_upper_bound = mean + 3 * std
target_lower_bound = mean - 3 * std

total_intermid = wear_limit[1] - wear_limit[0]
ten_percent_intermid = total_intermid / 10.0
plt.gca().axes.get_yaxis().set_visible(False)
plt.xlim([wear_limit[0],  wear_limit[1]])

plt.plot(x, np.zeros_like(x), 'x')
plt.plot(np.array([mean, mean + 2 * std, mean - 2 * std]),
         np.zeros_like(np.array([mean, mean + 2 * std, mean - 2 * std])), '|')

for i in x:
    plt.annotate(str(i), xy=(i, 0))
plt.annotate('mean', xy=(mean, 0))
plt.annotate('mean+3*std', xy=(target_upper_bound, 0))
plt.annotate('mean-3*std', xy=(target_lower_bound, 0))
plt.show()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-28 03:32:42

我不确定我完全明白你在尝试什么。看看这个例子是否能达到你想要的效果?

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt

#create random data
data=np.random.random(100)
std=np.std(data)

#display the individual data points
plt.scatter(data,np.zeros(data.shape[0]))

#use errorbar function to create symmetric horizontal error bar 
#xerr provides error bar length
#fmt specifies plot icon for mean value
#ms= marker size
#mew = marker thickness
#capthick = thickness of error bar end caps
#capsize = size of those caps

plt.errorbar(np.mean(data),0,xerr=3*std,fmt='|', ms=30,mew=2,capthick=2,capsize=10)

#set x axis limits
plt.xlim([-10,10])
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38620828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档