你可以使用
x_axis_type
='日期时间'
bokeh.plotting.figure
函数指示X轴将显示时间。
import pandas as pd
import numpy as np
import bokeh
import bokeh.plotting
N = 4
cats = 3
data = [[2,3,4], [2,2,3], [0,0,0], [1,2,3]]
df = pd.DataFrame(data, columns=['y0', 'y1', 'y2'])
print df
dates = ['2016-06-01','2016-06-02','2016-06-03','2016-06-04']
dt = [pd.datetime.strptime(x,'%Y-%m-%d') for x in dates]
def stacked(df):
df_top = df.cumsum(axis=1)
df_bottom = df_top.shift(axis=1).fillna({'y0': 0})[::-1]
df_stack = pd.concat([df_bottom, df_top], ignore_index=True)
return df_stack
areas = stacked(df)
colors = bokeh.palettes.brewer['Spectral'][areas.shape[1]]
x2 = np.hstack((dt[::-1], dt))
p = bokeh.plotting.figure(x_axis_type='datetime', y_range=(0, 10))
p.xaxis.formatter = bokeh.models.formatters.DatetimeTickFormatter(
days=["%Y-%m-%d"])
p.grid.minor_grid_line_color = '#eeeeee'
p.patches([x2] * areas.shape[1], [areas[c].values for c in areas],
color=colors, alpha=0.8, line_color=None)
bokeh.io.output_file('brewer.html', title='brewer.py example')
bokeh.io.show(p)