Skip to content

Instantly share code, notes, and snippets.

View extrospective's full-sized avatar

Mark Andersen extrospective

View GitHub Profile
@extrospective
extrospective / gist:0f4fe69304184d813f982035d9684452
Last active October 28, 2020 18:13
Seaborn stacked bar chart (extending Randy Zwitch approach)
def stacked_bar_chart(pivoted_df, stack_vals, level_values_field, chart_title, x_label, y_label, filename, color1, color2):
#
# stacked_bar_chart: draws and saves a barchart figure to filename
#
# pivoted_df: dataframe which has been pivoted so columns correspond to the values to be plotted
# stack_vals: the column names in pivoted_df to plot
# level_values_field: column in the dataframe which has the values to be plotted along the x axis (typically time dimension)
# chart_title: how to title chart
# x_label: label for x axis
# y_label: label for y axis