简体   繁体   English

散景+绘制多级柱线图

[英]bokeh + plotting line charts for multi level columns

I have a dataframe with columns as below after a pivot operation; 进行数据透视操作后,我有一个具有以下列的数据框;
And now I would like to plot line charts for each of these 8 columns using bokeh. 现在,我想使用bokeh为这8列中的每一个绘制折线图。

df.columns       
MultiIndex(levels=[['A', 'B', 'C'], ['EXT', 'IC', 'INT']],   
labels=[[0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 0, 1, 2, 0, 1, 2]],  
names=['SCHED', 'DInd'])

I was thinking of utilizing a for loop for this: 我当时正在考虑使用for循环:

from bokeh.charts import Line, output_file, show       
from bokeh.plotting import figure, show, output_file 
p1 = figure(x_axis_type="datetime", title="All Schedules")    
for col in df:        
        p1.line(df.index, df[col], legend=col)       
output_file("line.html", title="example")       
show(p1) 

However I cannot seem to call or select the multi level columns properly. 但是,我似乎无法正确调用或选择多级列。
Can you please assist 你能帮忙吗

In your case, you should've seen an error like 就您而言,您应该已经看到类似的错误

ValueError: expected an element of either String, Dict(Enum('expr', 'field', 'value', 'transform'), Either(String, Instance(Transform), Instance(Expression), List(String))) or List(String), got ('A', 'EXT')

which clearly shows that somewhere you pass an incorrect type. 这清楚地表明您在某个地方传递了错误的类型。 In this case, it's legend argument of the line glyph function. 在这种情况下,它是线字形函数的legend参数。 You can fix the error by eg writing legend=str(col) . 您可以通过编写legend=str(col)来纠正错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM