想要较粗的误差线
这是我使用 matplotlib
制作的 绘图。它使用 pylab
中的 bar
和 scatter
方法。 我有 3 个问题:
如何使误差线更宽?我可以看到 bar
中没有用于此目的的 API。 如何正确指定轴? 如何阻止 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()
替代文本 http://img210.imageshack.us/img210/8503 /screenshot20100206at703.png
Here's a plot I made using matplotlib
. It uses the bar
and scatter
methods from pylab
.
I have 3 issues:
How to make the error bars fatter? No API in bar
for this that I can see.
How to specify the axes properly?
How to stop the x-axis labels from showing?
The first is most important, as I have no idea. I guess one more thing would be, how to display the image here in SO? I've seen it done but don't know how.
Here is the code:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
误差线是用 bar 方法中的 errorbar 方法绘制的。它接受 elinewidth 参数,但看起来您无法通过 bar 方法调用传递它。我只会手动绘制它们。
要关闭 XAxis,请在调用 show 之前使用此命令:
这些更改使您的绘图如下所示:
替代文本 http://img690.imageshack.us/img690/5141/testfs.png< /a>
The error bars are drawn with the errorbar method from within the bar method. It accepts an elinewidth argument but it doesn't look like you can pass it through the bar method call. I would just draw them manually.
To turn the XAxis off use this before you call show:
These changes make your plot look like this:
alt text http://img690.imageshack.us/img690/5141/testfs.png
或者,要获得粗误差线,您可以通过“bar”方法传递“elinewidth”,如下所示:
Alternatively, to get fat error bars, you can pass "elinewidth" through the "bar"-method as follows: