2016-12-01 12 views
0

问题Python-如何将“胡须”添加到点图中?

我有一个由导入的数据构成的点图。一组数据显示了数据集中不同成员的时间序列方法,另一组数据显示了这些成员在采取平均值之前的每个时间步骤的标准差(SD)。我的顾问希望我添加显示+/- 1标准差的“胡须”,以代表平均值。我将在下面提供一个简化的工作示例。

的代码(例如)

import numpy as np 
import matplotlib.pyplot as plt 
%matplotlib inline 

#Generate some data 
x = np.empty((7,9)) 
for i in range(7): 
    x[i,:] = np.arange(1,10,(1+(i*.02))) 
print x 

#Find standard devs down each column 
std = np.std(x,axis=0)*5 
print std 

#Get the mean of x data down each column 
xmean = np.mean(x,axis=0) 
print xmean 

#Plot xmean data & x's stan. devs 
legendlabels = ['Mean of members','S.D. of members'] 
time = np.arange(0,9) 
fig, ax = plt.subplots(figsize=(11,6)) 
data1 = ax.scatter(time,xmean,s=70,color='k',marker='^') 
data2 = ax.scatter(time,std, s=70,color='k') 
ax.legend([data1,data2],legendlabels,loc=2) 
ax.grid() 
plt.show() 

SD乘以5个,从而晶须,当添加时,实际上可能是可见的。结果应该看起来像这样。 enter image description here

问题

如何添加晶须于表示+/- 1对应SD(下面圆的值)的三角形?考虑到我的实际数据没有显示沿y方向的范围,我不认为一个箱线图将工作最适合这个...

回答

2

您可以用添加误差线:

ax.errorbar(time, xmean, yerr=std) 

如果yerr是大小time的一维数组,误差棒是在+/- yerr相对吸引到你的数据(xmean)(http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar):

如果标量数字,LEN(N)阵列状物体,或者一个类似于数组的对象ct,相对于数据的+/-值相对 绘制误差线。

与您的代码,这导致:

enter image description here

欲了解更多信息,请参阅这些例子:http://matplotlib.org/1.2.1/examples/pylab_examples/errorbar_demo.html

+0

完美!谢谢! – ChristineB

相关问题