我正在为下表绘制一个mulit_index数据,图中的每一行都与列{10,11,12,21,26,27}中的数据相关
在我绘制multi_index数字之后:
我想在我的情节中添加图例,但是“temp”是multi_index pandas.DataFrame,我可以访问值{10,11,12,21,26,27},它会在每个查询中更改
下面是我的代码,请帮助我将传奇放入什么内容?
p=figure(x_axis_type="datetime")
table=pivot_table(data,index=['SDATE','SUBRACK_NO'],columns=['SLOT_NO'],values='ID_73393960',aggfunc={'mean'})
temp=table.query('SUBRACK_NO=="2"')
temp=temp.dropna(axis=1,how='all') # to remove all nan values from data
temp.reset_index(level=1, drop=True, inplace=True) # to drop index Subrack_no as it make problem for plotting
numlines=len(temp.columns)
mypalette=Spectral11[0:numlines]
p.multi_line(xs=[temp.index.values]*numlines,
ys=[temp[name].values for name in temp],
line_color=mypalette,
line_width=2,legend="**temp.columns.levels[1]**")
show(p) #show(gridplot([[p, p_filtered]]))
我的“临时”数据如下:
mean
SLOT_NO 10 11 12 21 26 27
SDATE
2018-04-12 01:00:00 30.178571 30.214286 29.107143 28.571429 28.714286 29.250000
2018-04-12 02:00:00 23.500000 24.250000 22.928571 25.214286 23.642857 22.785714
2018-04-12 03:00:00 18.642857 19.107143 18.678571 17.535714 17.857143 17.785714
2018-04-12 04:00:00 13.071429 13.178571 14.500000 13.214286 14.000000 14.142857
2018-04-12 05:00:00 12.321429 11.928571 13.464286 12.535714 12.785714 13.678571