Skip to content

Instantly share code, notes, and snippets.

@elena-roff
Created September 13, 2018 11:18
Show Gist options
  • Select an option

  • Save elena-roff/dde47a33a08445c284ecbe3bc2c0a7e3 to your computer and use it in GitHub Desktop.

Select an option

Save elena-roff/dde47a33a08445c284ecbe3bc2c0a7e3 to your computer and use it in GitHub Desktop.
Plotting correlations using groups from groupby
grouped_df = data.groupby('col')
num_subplots = grouped_df.ngroups
fig_corr = plt.figure(figsize=(15, 250))
count = 0
for name, group in grouped_df:
# limit by n of observations in a group
if group.shape[0] >= 100:
count = count + 1
ax_corr = fig_corr.add_subplot(round(num_subplots/3) + 1, 3, count)
corr_plot(
group['col1'].values, group['col2'].values,
ax_corr, title=name, x_lab='col1_name', y_lab='col2_name'
)
plt.tight_layout()
plt_show()
fig_corr.savefig('plot_name.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment