[英]bokeh patches stacked area chart with date
I am having trouble getting an stacked area chart with dates to populate. 我在获取带日期的堆积面积图时遇到麻烦。 I have followed the example located in: Stack Overflow Example
我遵循以下示例: 堆栈溢出示例
However this example does not populate the data. 但是,此示例未填充数据。 Here is my code:
这是我的代码:
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)
已知Bokeh的当前版本存在此问题: https : //github.com/bokeh/bokeh/issues/6458
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.