Created
November 11, 2022 16:58
-
-
Save audhiaprilliant/c92a0f631342333a3e53bd51ed1db317 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
| # ---------- MULTIPLOT ---------- | |
| # Create a grid for plots | |
| fig, ax = plt.subplots(figsize = (10, 5)) | |
| # Make another axes object for secondary y-Axis | |
| ax2 = ax.twinx() | |
| # Bar plot | |
| ax.bar( | |
| x = 'PaymentMethod', | |
| height = 'customerID', | |
| data = df_group_1, | |
| color = 'red' | |
| ) | |
| # Line plot | |
| ax2.plot( | |
| 'PaymentMethod', | |
| 'CummulativePerc', | |
| data = df_group_1, | |
| color = 'blue', | |
| marker = 'o' | |
| ); | |
| # Plot title | |
| plt.title('Number of Customer by Payment Method', fontsize = 16, fontweight = 'bold', fontstyle = 'italic'); | |
| # Vertical axis label (primary) | |
| ax.set_ylabel('# Customer', fontsize = 12, fontstyle = 'italic'); | |
| # Vertical axis label (secondary) | |
| ax2.set_ylabel('Percentage (%)', fontsize = 12, fontstyle = 'italic'); | |
| # Horizontal axis label | |
| ax.set_xlabel('Payment method', fontsize = 12, fontstyle = 'italic'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment