Created
November 11, 2022 17:00
-
-
Save audhiaprilliant/27c7dd01fd919dcaec042898f288bd83 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 rows & 2 columns) | |
| fig, ((ax1, ax2)) = plt.subplots(nrows = 1, ncols = 2, figsize = (10, 4.8)) | |
| # Bar plot - 1 | |
| ax1.bar( | |
| x = 'gender', | |
| height = 'customerID', | |
| data = df_group_2, | |
| color = 'red' | |
| ) | |
| # Bar plot - 2 | |
| ax2.bar( | |
| x = 'Contract', | |
| height = 'customerID', | |
| data = df_group_3, | |
| color = 'blue' | |
| ); | |
| # Titles | |
| ax1.set_title('# Customer by gender'); | |
| ax2.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