python画误差棒,Python在该点的上方和下方绘制具有不同值的误差线

在Python中,当数据的误差在点的上方和下方不同时,可以使用matplotlib库的errorbar函数来绘制误差棒。通过传递一个(2,n)形状的数组,其中第一行表示负误差,第二行表示正误差。例如,对于每个点,可以分别指定上方0.17和下方0.3的误差值。此外,如果每个点的误差不同,可以将误差值对按顺序排列并转置为(2,n)数组。" 104279001,7945445,调整数组顺序:奇数在前,偶数在后,"['数组处理', '算法', '数据结构']
摘要由CSDN通过智能技术生成

Warning: I'm very new to using python.

I'm trying to graph data using error bars but my data has different values for the error above and below the bar, i.e. 2+.75,2-.32.

import numpy as np

import matplotlib.pyplot as plt

# example data

x = (1,2,3,4)

y = (1,2,3,4)

# example variable error bar values

yerr = 0.2

plt.figure()

plt.errorbar(x, y, yerr,"r^")

plt.show()

But I want the error bar above the point to be a specific value like .17 and below the point to be a specific point like .3

Does anyone know how to do this?

Thanks!

解决方案

Like this:

plt.errorbar(x, y, np.array([[0.3]*len(x), [0.17]*len(x)]), fmt='r^')

Pass an array of shape (2,n) with the -errors on the first row and the +errors on the second

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值