Может быть что-то вроде этого (для Bokeh 1.1.0):
import pandas as pd
import datetime
import bokeh.plotting as bp
from bokeh.palettes import Category10
test_data = {'name': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'],
'date': [datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1),
datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1),
datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1), ],
'score': [100, 200, 300, 150, 400, 600, 150, 250, 400]}
plot_df = pd.DataFrame(test_data)
gby = plot_df.groupby('name')
names = list(gby.groups.keys())
palette = Category10[len(names)]
plot_df['color'] = [palette[names.index(x)] for i, sdf in gby for x in sdf['name']]
plot = bp.figure(x_axis_type = 'datetime')
gby.apply(lambda d: plot.line('date', 'score', line_color = d['color'].unique()[0], line_width = 3, legend = d['name'].unique()[0], source = d))
bp.show(plot)
или используя multi_line
:
import pandas as pd
import datetime
import bokeh.plotting as bp
from bokeh.palettes import Category10
from bokeh.models import ColumnDataSource
test_data = {'name': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'],
'date': [datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1),
datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1),
datetime.date(2010, 1, 1),
datetime.date(2010, 2, 1),
datetime.date(2010, 3, 1), ],
'score': [100, 200, 300, 150, 400, 600, 150, 250, 400]}
plot_df = pd.DataFrame(test_data)
gby = plot_df.groupby('name')
plot = bp.figure(x_axis_type = 'datetime')
x = [list(sdf['date']) for i, sdf in gby]
y = [list(sdf['score']) for i, sdf in gby]
source = ColumnDataSource(dict( x = x,
y = y,
legend = plot_df['name'].unique(),
color = Category10[len(plot_df['name'].unique())]))
plot.multi_line('x', 'y', legend = 'legend', line_color = 'color', line_width = 3, source = source)
bp.show(plot)
Результат (оба варианта):