多索引图p中的绘图图例

2024-05-29 00:28:09 发布

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

我正在为下表绘制一个多索引数据,图中的每一行都与{10,11,12,21,26,27}列中的数据相关

my data as "temp"

在绘制多索引图之后:

multi_index figure plot

我想把图例添加到我的绘图中,但是“temp”是多索引的1.数据帧,我可以访问值{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

Tags: columns数据nodataindexaslinetable
1条回答
网友
1楼 · 发布于 2024-05-29 00:28:09

看起来你已经很接近你想要的了。使用已有的数据,看起来有层次结构的列,mean是上层。假设您的数据帧是df

df.mean.plot()

应返回以下内容:

plot

这就是你想要的吗?你知道吗

相关问题 更多 >

    热门问题