Last active
November 9, 2022 14:42
-
-
Save audhiaprilliant/82e621b2c95f125218372da5a64beb0a to your computer and use it in GitHub Desktop.
Matplotlib 101 - Basic Introduction for Python Beginner
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
| # ---------- 3rd ITERATION - REMOVE FRAMES AND RESET THE VERTICAL TICKS ---------- | |
| # Figure size | |
| fig = plt.figure(figsize = (10, 4.8)) | |
| # Bar plot | |
| bar_fig = plt.bar( | |
| x = 'PaymentMethod', | |
| height = 'customerID', | |
| data = df_group_1, | |
| width = 0.5 | |
| ); | |
| # Set colors | |
| colors = ['#981220', '#80797C', '#80797C', '#80797C'] | |
| for i in range(len(colors)): | |
| bar_fig[i].set_color(colors[i]) | |
| # Set y-Limit | |
| plt.ylim([0, 3000]); | |
| # Set y-ticks | |
| plt.yticks( | |
| ticks = range(0, 3000, 500), | |
| labels = range(0, 3000, 500) | |
| ) | |
| # Remove right & top frames from matplotlib | |
| plt.gca().spines['top'].set_visible(False) | |
| plt.gca().spines['right'].set_visible(False) | |
| # Add values | |
| for bar in bar_fig: | |
| plt.annotate( | |
| text = bar.get_height(), | |
| xy = ( | |
| bar.get_x() + 0.14, | |
| bar.get_height() + 50), | |
| fontsize = 12 | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment