Skip to content

Instantly share code, notes, and snippets.

@andrewm4894
Created February 6, 2019 17:22
Show Gist options
  • Save andrewm4894/579315eca6a85336f2d93f9018aad498 to your computer and use it in GitHub Desktop.
Save andrewm4894/579315eca6a85336f2d93f9018aad498 to your computer and use it in GitHub Desktop.
def plot_lines_multi(df,lw=2,pw=700,ph=400,t_str="hover,save,pan,box_zoom,reset,wheel_zoom",t_loc='above'):
'''...
'''
source = ColumnDataSource(df)
col_names = source.column_names
p = figure(x_axis_type="datetime",plot_width=pw, plot_height=ph,toolbar_location=t_loc, tools=t_str)
p_dict = dict()
for col, c, col_name in zip(df.columns,color,col_names):
p_dict[col_name] = p.line('index', col, source=source, color=c,line_width=lw)
p.add_tools(HoverTool(
renderers=[p_dict[col_name]],
tooltips=[('datetime','@index{%Y-%m-%d %H:%M:%S}'),(col, f'@{col}')],
formatters={'index': 'datetime'}
))
legend = Legend(items=[(x, [p_dict[x]]) for x in p_dict])
p.add_layout(legend,'right')
show(p)
output_notebook()
plot_lines_multi(df._get_numeric_data())
@rchurt
Copy link

rchurt commented Jul 9, 2020

@andrewm4894 I think line 8 should be for col, c, col_name in zip(df.columns,color,col_names[1:]): because col and col_name are off by one

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