Created
September 13, 2018 11:18
-
-
Save elena-roff/dde47a33a08445c284ecbe3bc2c0a7e3 to your computer and use it in GitHub Desktop.
Plotting correlations using groups from groupby
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
| 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