Skip to content

Instantly share code, notes, and snippets.

@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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yrevar
yrevar / matplotlib_cheat_sheet.ipynb
Last active April 11, 2019 21:35
Matplotlib Cheat Sheet. Adapted from: Hilpisch, Y. (2012).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import os
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib as mpl
# plot title
mpl.rcParams['axes.titlesize'] = 18