怎么用python画直方图中怎么设置数据范围_如何用python在直方图中绘制置信区间条?...

我计算了直方图中显示的一些数据的置信区间。

现在,我想在情节中加入置信度条,但我不知道怎么做。有没有人给我建议如何继续?在import matplotlib.pyplot as plt

from functools import reduce

plt.style.use('ggplot')

from scipy.stats import sem, t

from scipy import mean

import seaborn as sns

List_slopes= [[0.0437712648015943], [0.03891732777088522], [0.04873966717541519], [0.06834041111023302], [0.03290835239919912], [0.05676673320560569], [0.04193367376660084], [0.05453567515132543],

[0.0436988106026637], [0.05639531551298649], [0.033151533411499554], [0.05312718258689977], [0.03201472087883465], [0.06138900127756917], [0.04084566472094725], [0.030980452931883645],

[0.03490031676420862], [0.05617484928592166], [0.05756062483863055], [0.05062138233057321], [0.037458909465997274], [0.0452444541408649], [0.031985252895496544], [0.05202456296370903],

[0.054154933324027967], [0.052119386421266026], [0.03637328841280627], [0.052831824786532394], [0.05250896675489661], [0.030371934074959257], [0.05559661606514884], [0.0524023454048075]

, [0.05716250142416688], [0.04272492198584081], [0.05737607811682808], [0.03440778732820213], [0.04386663383861987], [0.0526401870652505], [0.05718775471785554], [0.05862797457176922],

[0.025116204881676027], [0.05158014618741805], [0.03764036354269462], [0.037389249896867205], [0.062041377418890396], [0.04436736176610321]]

confidence = 0.95

n = len(List_slopes)

average = mean(List_slopes) # average, mean

print(average)

std_err = sem(List_slopes) # standard deviation

print(std_err)

confidence_interval = std_err * t.ppf((1 + confidence) / 2, n - 1) # t.pp is equivalent to Excel TINV(2*0.05,999)

print(confidence_interval)

Lower_CI = average - confidence_interval

Upper_CI = average + confidence_interval

sns.distplot(List_slopes, kde=True)

plt.xlabel("Slopes ")

plt.ylabel("Frequency of Slopes")

plt.text(.5, .75, str(round(confidence * 100)) + '% Confidence Interval', fontsize=25, color='black', ha='center')

plt.text(.5, .35, str(round(Lower_CI[0], 2)) + ' to ' + str(round(Upper_CI[0], 2)), fontsize=25, color='black', ha='center')

plt.show()

在这个图中,我把我的代码产生的数字。我想画出0.04和0.05这两条线,因为它们代表一系列误差线。我的意思是我要画出下逖CI和Upper逖CI。在

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值