在matplotlib中使用透明度和多种颜色显示三维条形图

2024-10-01 07:36:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧,其中行表示一天中的小时数,列表示时间频率。其目的是创建一个三维条形图,每个列代表不同的颜色。我的数据帧如下

frec=pd.read_csv('tiempo.csv', parse_dates='Horas',index_col='Horas')
frec.index=[date.strftime('%H:%M') for date in frec.index]

frec
         Inicio  MaxExt  Fin
18:00       1       1    1
19:00       0       0    3
20:00       1       1    1
21:00       1       1    0
22:00       3       1    0
23:00       9       1    0
00:00       8       3    2
01:00       2       0    1
02:00       3       8    1
03:00       5       3    2
04:00       6       2    6
05:00       6       6    5
06:00       5       6    4
07:00       5       7    2
08:00       2       4    5
09:00       1       6    6
10:00       0       3    2
11:00       2       5    5
12:00       4       1    9
13:00       2       4    2
15:00       0       2    3
14:00       3       2    4
15:00       0       2    3
16:00       1       1    3
17:00       0       2    3 

下面几行代码试图创建绘图

^{pr2}$

enter image description here

我如何得到一个每列都用不同颜色绘制的图?。也就是说,Inicio列的条是蓝色的,MaxExt列的条是红色的,Fin列的条是黄色的


Tags: csv数据目的dateindex颜色时间频率
1条回答
网友
1楼 · 发布于 2024-10-01 07:36:16

通过以下方法创建colors

values = np.linspace(0.2, 1., frec.shape[0])
cmaps = [cm.Blues, cm.Reds, cm.Greens]
colors = np.hstack([c(values) for c in cmaps]).reshape(-1, 4)

输出如下:

enter image description here

相关问题 更多 >