影像组学视频学习笔记[44(End)]-带95%置信区间的折线图、Li‘s have a solution and plan.

本文介绍两种方法来绘制带有95%置信区间的折线图,第一种方法使用Python的matplotlib和scipy库实现,第二种方法则通过Seaborn包简化流程。示例中展示了如何加载数据并进行可视化处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者:北欧森林
链接:https://www.jianshu.com/p/971eeaa03ec9
来源:简书,已获授权转载

本笔记来源于B站Up主: 有Li 的影像组学系列教学视频
本节(44)主要内容:带95%置信区间的折线图

Method 1

# Time Series with Error Bands
## In this approach, the mean of the number of orders is denoted by the white line. 
## And a 95% confidence bands are computed and drawn around the mean.

from scipy.stats import sem
import pandas as pd
import matplotlib.pyplot as plt

Import Data

df = pd.read_csv(“https://raw.githubusercontent.com/selva86/datasets/master/user_orders_hourofday.csv”)
df_mean = df.groupby(‘order_hour_of_day’).quantity.mean()
df_se = df.groupby(‘order_hour_of_day’).quantity.apply(sem).mul(1.96)

Plot

plt.figure(figsize=(16,10), dpi= 80)
plt.ylabel("# Orders", fontsize=16)
x = df_mean.index
plt.plot(x, df_mean, color=“white”, lw=2)
plt.fill_between(x, df_mean - df_se, df_mean + df_se, color="#3F5D7D")

Decorations

Lighten borders

plt.gca().spines[“top”].set_alpha(0)
plt.gca().spines[“bottom”].set_alpha(1)
plt.gca().spines[“right”].set_alpha(0)
plt.gca().spines[“left”].set_alpha(1)
plt.xticks(x[::2], [str(d) for d in x[::2]] , fontsize=12)
plt.title(“User Orders by Hour of Day (95% confidence)”, fontsize=22)
plt.xlabel(“Hour of Day”)

s, e = plt.gca().get_xlim()
plt.xlim(s, e)

Draw Horizontal Tick lines

for y in range(8, 20, 2):
plt.hlines(y, xmin=s, xmax=e, colors=‘black’, alpha=0.5, linestyles="–", lw=0.5)

plt.show()

在这里插入图片描述

Method 2 (Seaborn package)

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv(“https://raw.githubusercontent.com/selva86/datasets/master/user_orders_hourofday.csv”)

plt.figure(figsize=(16,10),dpi = 80)
x = df[“order_hour_of_day”]
y = df[“quantity”]
sns.lineplot(x,y,ci=95
#,err_style=None
)

plt.show()

在这里插入图片描述

示例数据的模样:
 
在这里插入图片描述

参考资料:
Top 50 matplotlib Visualizations – The Master Plots (with full python code)

End

李任远博士在B站发布的影像组学视频教程系列正式结束啦~~今后将带来关于脑功能磁共振与深度学习的更多内容,敬请关注。对影像组学科研有进一步学习、指导需求的,欢迎加入我们的付费手把手课程,详情可以点此前去查看

小李的“手把手”影像组学课程介绍
http://radiomicsworld.com/d/244-0
网盘链接:https://pan.baidu.com/s/16eDy5Zho9I1uG53FKsY8Kw 密码:8njd
商品链接 https://weidian.com/item.html?itemID=4294775730

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值