栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Python的散景图中添加误差线?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Python的散景图中添加误差线?

编辑:这现在内置到Bokeh中,请参阅文档:

https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#whiskers

https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#bands

有关完整的示例,请参见https://stackoverflow.com/a/46517148/3406693。


也许有点晚了,但我今天也想这样做。

令人遗憾的是bokeh本身不提供此功能。

import numpy as npfrom bokeh.plotting import figure, show, output_file# some pseudo dataxs = np.linspace(0, 2*np.pi, 25)yerrs = np.random.uniform(0.1, 0.3, xs.shape)ys = np.sin(xs) + np.random.normal(0, yerrs, xs.shape)output_file('bokeh_errorbars.html')# plot the pointsp = figure(title='errorbars with bokeh', width=800, height=400)p.xaxis.axis_label = 'x'p.yaxis.axis_label = 'y'p.circle(xs, ys, color='red', size=5, line_alpha=0)# create the coordinates for the errorbarserr_xs = []err_ys = []for x, y, yerr in zip(xs, ys, yerrs):    err_xs.append((x, x))    err_ys.append((y - yerr, y + yerr))# plot themp.multi_line(err_xs, err_ys, color='red')show(p)

结果如下:

可能需要将其用作这样的功能:

def errorbar(fig, x, y, xerr=None, yerr=None, color='red',   point_kwargs={}, error_kwargs={}):  fig.circle(x, y, color=color, **point_kwargs)  if xerr:      x_err_x = []      x_err_y = []      for px, py, err in zip(x, y, xerr):          x_err_x.append((px - err, px + err))          x_err_y.append((py, py))      fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs)  if yerr:      y_err_x = []      y_err_y = []      for px, py, err in zip(x, y, yerr):          y_err_x.append((px, px))          y_err_y.append((py - err, py + err))      fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/634166.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号