Created
January 25, 2019 15:35
-
-
Save admond1994/7dd47fb520404959f5dde57e8a4a945c to your computer and use it in GitHub Desktop.
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
| fig = plt.figure(figsize=(15, 7)) | |
| ax1 = fig.add_subplot(111) | |
| ax1.set_xlabel('Month',fontsize=15) | |
| ax1.set_ylabel('Total Amount Spent ($)',fontsize=15) | |
| ax1.set_title('Total Amount Spent for different Months',fontsize=15) | |
| ax1.bar(df.groupby(by=['year_month'])['amount_spent'].sum().index.tolist()[1:], | |
| df.groupby(by=['year_month'])['amount_spent'].sum()[1:], | |
| alpha=0.85, | |
| label='Amount Spent by Month') | |
| #---------------- | |
| ax2 = ax1.twinx() | |
| ax2.set_ylabel('Percentage Change of Total Amount Spent (%)',fontsize=15) | |
| ax2.plot(df.groupby(by=['year_month'])['amount_spent'].sum().index.tolist()[1:], | |
| df.groupby(by=['year_month'])['amount_spent'].sum()[1:].pct_change().fillna(0)*100, | |
| label='Percentage change of total amount spent (%)', | |
| color='red') | |
| ax1.legend(loc='upper left') | |
| ax2.legend(loc='upper right') | |
| fig.tight_layout() | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment