这是我用matplotlib做的一个plot。它使用来自pylab的bar和scatter方法。我有3个问题:
如何让错误条变得更胖?据我所知,在bar中没有这方面的接口。如何正确指定轴?如何停止显示x轴标签?
第一个是最重要的,因为我不知道。我猜还有一件事是,如何在SO中显示图像?我已经看过了,但不知道怎么做。
代码如下:
import numpy as np
from pylab import *
data1 = np.linspace(12,22,7)
data2 = np.random.normal(loc=15,scale=5,size=10)
data3 = [11,12,18,19,20,26,27]
data = [data1,np.abs(data2),data3]
# n = number of groups
def layout(n,r=7):
s = r**2 # r = radius of each data point
#layout from 1 to 100
margin = 5
spacer = 10
group_width = (100 - 2*margin - (n-1)*spacer)*1.0/n
dot_width = r
bar_width = group_width - dot_width
current = margin
rL = list()
for i in range(n):
rL.append(current) # x for point
rL.append(current + 3) # x for bar
current += group_width + spacer
return s, bar_width, rL
s, w, xlocs = layout(len(data))
for group in data:
x = xlocs.pop(0)
for e in group:
scatter(x,e,s=s,color='k')
m = np.mean(group)
e = np.std(group)
x = xlocs.pop(0)
o = bar(x,m,width=w,color='0.6',
yerr=e, ecolor='k')
show()alt text http://img210.imageshack.us/img210/8503/screenshot20100206at703.png
发布于 2010-02-07 10:28:16
使用errorbar方法从bar方法中绘制误差条。它接受一个elinewidth参数,但是看起来您不能通过bar方法调用来传递它。我只会手动绘制它们。
o, = bar(x,m,width=w,color='0.6', yerr=None) # note the comma after the o
eBarX = o.get_x()+o.get_width()/2.0
eBarY = o.get_height()
errorbar(eBarX,eBarY,e,capsize=7,elinewidth=6,ecolor='k')要关闭XAxis,请在调用show之前使用以下命令:
axes().xaxis.set_visible(False)这些更改使您的图看起来如下所示:alt text http://img690.imageshack.us/img690/5141/testfs.png
发布于 2015-03-18 21:50:15
或者,要获得较大的错误条,您可以通过“-method”传递"elinewidth“,如下所示:
o = bar(x,m,width=w,color='0.6', error_kw={"elinewidth":5}, yerr=e)https://stackoverflow.com/questions/2215358
复制相似问题