想要较粗的误差线

发布于 2024-08-20 12:07:40 字数 1528 浏览 3 评论 0原文

这是我使用 matplotlib 制作的 绘图。它使用 pylab 中的 barscatter 方法。 我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫卆 2024-08-27 12:07:40

误差线是用 bar 方法中的 errorbar 方法绘制的。它接受 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)

这些更改使您的绘图如下所示:
替代文本 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.

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')

To turn the XAxis off use this before you call show:

axes().xaxis.set_visible(False)

These changes make your plot look like this:
alt text http://img690.imageshack.us/img690/5141/testfs.png

回眸一笑 2024-08-27 12:07:40

或者,要获得粗误差线,您可以通过“bar”方法传递“elinewidth”,如下所示:

o = bar(x,m,width=w,color='0.6', error_kw={"elinewidth":5}, yerr=e)

Alternatively, to get fat error bars, you can pass "elinewidth" through the "bar"-method as follows:

o = bar(x,m,width=w,color='0.6', error_kw={"elinewidth":5}, yerr=e)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文