Created
October 10, 2016 14:11
-
-
Save stringfellow/1f0a7ab327de326c805e23966fb975ec to your computer and use it in GitHub Desktop.
Showing how to make a Bokeh stacked area with hover labels per-series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stacked_area(df, colours, series_noun, **kwargs): | |
"""Return a stacked area plot.""" | |
columns = df.columns | |
areas = stacked(df, columns) | |
x2 = np.hstack((df.index[::-1], df.index)) | |
p = figure( | |
width=900, height=600, tools=[ | |
SaveTool(), | |
HoverTool(tooltips=[(series_noun, "@name")]) | |
], | |
x_axis_type="datetime", | |
**kwargs | |
) | |
p.grid.minor_grid_line_color = '#eeeeee' | |
ys = [] | |
xs = [] | |
names = [] | |
for col in columns: | |
ys.append(areas[col]) | |
xs.append(x2) | |
names.append(col) | |
source = ColumnDataSource(data=dict( | |
x=xs, | |
y=ys, | |
name=names, | |
)) | |
p.patches( | |
'x', 'y', source=source, color=colours | |
) | |
p.xaxis.formatter = DatetimeTickFormatter( | |
formats=dict(days=["%a\n%d %b"]) | |
) | |
return p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
whta is stacked here? where is it imported from?stacked(df, columns)