Last active
July 14, 2019 05:00
-
-
Save gary136/1e91e9311138156c7bc57667935fd95f to your computer and use it in GitHub Desktop.
sales_visualization
This file contains 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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import matplotlib | |
import matplotlib.dates as mdates | |
yoy = df['YOY'] | |
sales_this_month = df['Sales_This_Month'] | |
zero = pd.Series(np.zeros(len(yoy))) | |
zero.index = yoy.index | |
# python matplotlib 繪製雙Y軸曲線圖 - https://reurl.cc/y3ZzM | |
fig, ax1 = plt.subplots(figsize=(15, 8)) | |
ax1.bar(zero.index, sales_this_month, width=15, label='當月營收', color = 'wheat') | |
ax1.set_ylabel('Sales', fontsize=16) | |
ax1.get_yaxis().set_major_formatter( | |
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ','))) | |
ax2 = ax1.twinx() | |
ax2.plot(yoy, label='營收年增百分比') | |
ax2.plot(zero, '--', color='black') | |
ax2.set_xlabel('Year', fontsize=12) | |
ax2.set_ylabel('YOY(%)', fontsize=16) | |
fig.suptitle('歷史營收/年增率', fontsize=18) | |
fig.legend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment