Skip to content

Instantly share code, notes, and snippets.

@stringfellow
Created October 10, 2016 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringfellow/1f0a7ab327de326c805e23966fb975ec to your computer and use it in GitHub Desktop.
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
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
@surajbharadwaj
Copy link

whta is stacked here? where is it imported from?stacked(df, columns)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment