Last active
August 31, 2019 14:33
-
-
Save FBosler/05f9c6b9ef297b22be0c8104970472b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 draw_heatmap(data,inner_row, inner_col, outer_row, outer_col, values): | |
sns.set(font_scale=1) | |
fg = sns.FacetGrid( | |
data, | |
row=outer_row, | |
col=outer_col, | |
margin_titles=True | |
) | |
position = left, bottom, width, height = 1.4, .2, .1, .6 | |
cbar_ax = fg.fig.add_axes(position) | |
fg.map_dataframe( | |
draw_heatmap_facet, | |
x_col=inner_col, | |
y_col=inner_row, | |
values=values, | |
cbar_ax=cbar_ax, | |
vmin=0, | |
vmax=.4 | |
) | |
fg.fig.subplots_adjust(right=1.3) | |
plt.show() | |
def draw_heatmap_facet(*args, **kwargs): | |
data = kwargs.pop('data') | |
x_col = kwargs.pop('x_col') | |
y_col = kwargs.pop('y_col') | |
values = kwargs.pop('values') | |
d = data.pivot(index=y_col, columns=x_col, values=values) | |
annot = round(d,4).values | |
cmap = sns.color_palette("RdYlGn",30) | |
# cmap = sns.color_palette("PuBu",30) alternative color coding | |
sns.heatmap(d, **kwargs, annot=annot, center=0, fmt=".1%", cmap=cmap, linewidth=.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment