気づけば夜になっていた。

 申し訳ないが今日はあまりpythonの勉強はしなかった。美容院に行って、散歩したあとに読書していたらあっという間に夜になっていたんだ。その代わり、「ストレスフリー超大全」は無事に一度読了した。明日、もう一週読んで、感想を書きたいと思う。

 pythonに関しては「matplotlibの使い方」のレッスンが終了した。明日からはpandasを用いたデータ処理に入るので、いよいよデータサイエンス感が出てきそうだ。

import matplotlib.pyplot as plt
plt.style.use('seaborn-darkgrid')

month = [4, 5, 6, 7, 8, 9]
sales_new = [11, 17, 12, 24, 35, 58] # 新規顧客の売上(千円)
sales_old = [102, 141, 127, 167, 202, 205] # 既存顧客の売上(千円)
rate_new = [round(new_ / (new_ + old) * 100)
           for new_, old in zip(sales_new, sales_old)]
labels = ['Sales & New rate', 'Sales(1000 yen)', 'New rate(%)']

fig,ax1=plt.subplots()
ax1.set_title(labels[0])
ax2=ax1.twinx()
ax2.grid(False)

ax1.bar(month,sales_old,label="Old")
ax1.bar(month,sales_new,label="New",bottom=sales_old)
ax1.set_xlabel("Month")
ax1.set_ylabel(labels[1])
ax1.legend()

ax2.plot(month,rate_new,color="r")
ax2.set_ylabel(labels[2])
ax2.set_ylim(bottom=0);
plt.show()

画像1


この記事が気に入ったらサポートをしてみませんか?