爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6693|回复: 11

MeteoInfoLab脚本示例:误差棒 - errorbar

[复制链接]

新浪微博达人勋

发表于 2015-12-25 10:08:25 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 MeteoInfo 于 2019-3-6 08:58 编辑

更新了MeteoInfoLab的功能,可以使用errorbar()函数绘制误差棒(error bar)图。

固定x, y误差:
  1. x = arange(0.1, 4, 0.5)
  2. y = exp(-x)
  3. errorbar(x, y, fmt='b', xerr=0.2, yerr=0.4)
  4. title('Fixed error values example')


errorbar_1.png

变化y误差:
  1. x = arange(0.1, 4, 0.5)
  2. y = exp(-x)
  3. # example error bar values that vary with x-position
  4. error = 0.1 + 0.2 * x
  5. errorbar(x, y, yerr=error, fmt='b-o')
  6. title('Variable error bar values example')


errorbar_2.png

为直方图(bar)加误差棒:
  1. menMeans = [20, 35, 30, 35, 27]std_men = (2, 3, 4, 1, 2)
  2. n = len(menMeans)
  3. ind = arange(n)
  4. width = 0.35
  5. gap = 0.06
  6. bar(ind, menMeans, width, yerr=std_men, color='r', ecolor='b', label='Men')
  7. for j in range(n):
  8.     text(ind[j] + width / 4, menMeans[j] + 2, str(menMeans[j]))

  9. womenMeans = [25, 32, 34, 20, 25]
  10. std_women = (3, 5, 2, 3, 3)
  11. bar(ind + width + gap, womenMeans, width, yerr=std_women, color='y', ecolor='g', label='Women')
  12. for j in range(n):
  13.     text(ind[j] + + width + gap + width / 4, womenMeans[j] + 2, str(womenMeans[j]))

  14. xlim(-0.2, 5)
  15. ylim(0, 40)
  16. ylabel('Scores')
  17. xticks(ind + width + gap / 2, ['G1','G2','G3','G4','G5'])
  18. legend()
  19. title('Scores by group and gender')


bar_1.png

双Y轴Bar图+误差棒:
  1. menMeans = [20, 35, 30, 35, 27]
  2. std_men = (2, 3, 4, 1, 2)
  3. n = len(menMeans)
  4. ind = arange(n)
  5. width = 0.35
  6. gap = 0.06
  7. ax1 = axes(position=[0.11,0.1,0.75,0.8])
  8. yaxis(ax1, color='r')
  9. bar1 = bar(ind, menMeans, width, yerr=std_men, color='r', ecolor='b', label='Men')
  10. for j in range(n):
  11.     text(ind[j] + width / 4, menMeans[j] + 2, str(menMeans[j]))
  12. xlim(-0.2, 5)
  13. ylim(0, 40)
  14. ylabel('Men Scores', color='r')
  15. xticks(ind + width + gap / 2, ['G1','G2','G3','G4','G5'])
  16. title('Scores by group and gender')

  17. womenMeans = array([25, 32, 34, 20, 25])
  18. womenMeans = womenMeans * 2
  19. std_women = (3, 5, 2, 3, 3)
  20. ax2 = twinx(ax1)
  21. yaxis(ax2, color='b')
  22. bar2 = bar(ind + width + gap, womenMeans, width, yerr=std_women, color='b', ecolor='g', label='Women')
  23. for j in range(n):
  24.     text(ind[j] + + width + gap + width / 4, womenMeans[j] + 2, str(womenMeans[j]))
  25. xlim(-0.2, 5)
  26. ylim(0, 80)
  27. ylabel('Women Scores', color='b')

  28. legend(bar1+bar2)


bar_yy.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-25 13:38:09 | 显示全部楼层
王老师,第三张图可以改成双Y轴柱状图加误差棒么?谢谢!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-12-25 15:26:04 | 显示全部楼层
rceclx 发表于 2015-12-25 13:38
王老师,第三张图可以改成双Y轴柱状图加误差棒么?谢谢!

在1楼加入了这种图的示例。需要重新下载MeteoInfo_Java_1.2.9R2_Files.zip。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-12-25 16:04:28 | 显示全部楼层
MeteoInfo 发表于 2015-12-25 15:26
在1楼加入了这种图的示例。需要重新下载MeteoInfo_Java_1.2.9R2_Files.zip。

王老师,棒棒哒!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-1-9 09:33:13 | 显示全部楼层
{:5_213:}{:5_213:}{:5_213:}
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2016-11-30 18:46:04 | 显示全部楼层
{:5_213:}学习了
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2019-3-5 21:43:09 | 显示全部楼层
王老师,您好,我想把error-bar图与plot点线图画在一起,但是legend显示不出来,总是报错,请王老师指点迷津。 r = gca.legend(*args, **kwargs)
AttributeError: 'NoneType' object has no attribute 'legend'
脚本如下:menMeans = [50, 62, 70, 63, 50]
std_men = (41, 26, 39, 25, 19)
n = len(menMeans)
ind = arange(n)
width = 0.5
gap = 0.06
ax1 = axes(position=[0.11,0.1,0.75,0.8])
yaxis(ax1, color='k')
bar1 = bar(ind, menMeans,width, yerr=std_men, color=(160,234,255), linewidth=0,edgecolor=(160,234,255), label='Men')

xlim(-0.5, 5)
ylim(0, 130)

ylabel(u'人数',fontname=u'宋体',fontsize=18,bold='True', color='k')
xticks(ind+width/2, ['(0,0.5]','(0.5,1]','(1,2.5]','(2.5,5]','(5,15]'])

ax2 = twinx(ax1)
yaxis(ax2, color='k')
t=ind+width/2
s2 = [39,21,20,4,4]
line1=plot(t, s2,'.-b')
ylabel(u'天数',fontname=u'宋体',fontsize=18,bold='True', color='k')
xlim(-0.5, 5)
ylim(0, 45)
show()
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2019-3-6 08:53:31 | 显示全部楼层
Linda.W 发表于 2019-3-5 21:43
王老师,您好,我想把error-bar图与plot点线图画在一起,但是legend显示不出来,总是报错,请王老师指点迷 ...

legend([bar1[0], line1)
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-3-6 10:14:41 | 显示全部楼层
好的,谢谢王老师。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-3-15 15:51:53 | 显示全部楼层
王老师,我在melab官网上看到堆积柱状图的示例脚本,两个堆叠在一起,使用bottom语句,如何实现多个(5~6)柱状图堆积?谢谢老师。
menMeans = [20, 35, 30, 35, 27]
n = len(menMeans)
ind = arange(n)
width = 0.35
bar(ind, menMeans, width, color='r', ecolor='b', label='Men')

womenMeans = [25, 32, 34, 20, 25]
bar(ind, womenMeans, width, bottom=menMeans, color='y', ecolor='g', label='Women')

xlim(-0.2, 5)
ylim(0, 80)
ylabel('Scores')
xticks(ind + width / 2, ['G1','G2','G3','G4','G5'])
legend()
title('Scores by group and gender')
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表