散景补丁堆积区域图表与日期

时间:2018-02-06 15:49:28

标签: time charts bokeh patch

我无法获得包含日期的堆积区域图表。我按照Stack Overflow Example

中的示例进行了操作

但是,此示例不会填充数据。这是我的代码:

    data = {'A': {0: 30.0, 1: 40.0, 2: 39.0, 3: 30.0, 4: 21.0},
 'All': {0: 374.0, 1: 414.0, 2: 373.0, 3: 362.0, 4: 351.0},
 'B': {0: 237.0, 1: 246.0, 2: 216.0, 3: 187.0, 4: 202.0},
 'C': {0: 93.0, 1: 120.0, 2: 103.0, 3: 136.0, 4: 118.0},
 'D': {0: 14.0, 1: 8.0, 2: 15.0, 3: 9.0, 4: 9.0},
 'DEPT': {0: 'All', 1: 'All', 2: 'All', 3: 'All', 4: 'All'},
 'E': {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 1.0},
 'YEAR_WEEK': {0: '2017_01',
  1: '2017_02',
  2: '2017_03',
  3: '2017_04',
  4: '2017_05'}}

df_all = pd.DataFrame(data)

output_notebook()

def  stacked(df):
    df_top = df.cumsum(axis=1)
    df_bottom = df_top.shift(axis=1).fillna({'A': 0})[::-1]
    df_stack = pd.concat([df_bottom, df_top], ignore_index=True)
    return df_stack

areas = stacked(df_all[['A','D','B','C','E']])

colors = brewer['Spectral'][areas.shape[1]]

x2 = np.hstack((df_all.index[::-1], df_all.index))


source = ColumnDataSource(df_all)

"""This works and shows data but does not have date tag"""
p = figure()

"""This does not show data but chart does have date tag"""
# p = figure(x_range = FactorRange(factors = df_all.YEAR_WEEK.tolist()), y_range =(0,1200))

p.patches([x2] * areas.shape[1], [areas[c].values for c in areas],color=colors, alpha=0.8, line_color=None)


p.xaxis.major_label_orientation = 'vertical'

show(p)

1 个答案:

答案 0 :(得分:1)

众所周知,当前版本的Bokeh存在此问题:https://github.com/bokeh/bokeh/issues/6458