Last active
November 11, 2022 17:01
-
-
Save audhiaprilliant/98923124353474c752e64145b949192a to your computer and use it in GitHub Desktop.
Matplotlib 102 - Basic Introduction to Multiplot, Subplot and Gridspec
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
| # ---------- SUBPLOT (1 ROWS, 2 COLUMNS) ---------- | |
| # Create a grid for plots (1 row & 2 columns) | |
| fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = (10, 4.8)) | |
| # Bar plot - 1 | |
| ax[0].bar( | |
| x = 'gender', | |
| height = 'customerID', | |
| data = df_group_2, | |
| color = 'red' | |
| ) | |
| # Bar plot - 2 | |
| ax[1].bar( | |
| x = 'Contract', | |
| height = 'customerID', | |
| data = df_group_3, | |
| color = 'blue' | |
| ); | |
| # Titles | |
| ax[0].set_title('# Customer by gender'); | |
| ax[1].set_title('# Customer by contract'); | |
| # Title the figure | |
| plt.suptitle('# Customer in Telco XYZ', fontsize = 14, fontweight = 'bold'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment