In [22]:
import pandas as pd
import matplotlib.pyplot as plt
import os
In [23]:
base_url = 'http://raw.githubusercontent.com/practical-jupyter/sample-data/master/anime/'
anime_stock_returns_csv = os.path.join(base_url, 'anime_stock_returns.csv')
anime_stock_returns_df = pd.read_csv(anime_stock_returns_csv, index_col=0)

ax = anime_stock_returns_df.plot()
ax.set_title('stock returns')
plt.show() # 折れ線グラフの作成
In [24]:
# Y軸の範囲が異なる折れ線グラフ
anime_stock_price_csv = os.path.join(base_url, 'anime_stock_price.csv')
anime_stock_price_df = pd.read_csv(anime_stock_price_csv, index_col=0)
ax = anime_stock_price_df.plot(secondary_y=['IG Port'])
ax.set_title('secondary_y')
ax.set_ylabel('TOEI ANIMATION')
ax.right_ax.set_ylabel('IG Port')
plt.show()
In [25]:
# 複数の図に分割
# subplotsを使用した折れ線グラフ
ax1, ax2 = anime_stock_price_df.plot(subplots=True)
ax1.set_title('subplot1')
ax2.set_title('subplot2')
plt.show()
In [26]:
# 散布図を作成
anime_master_csv = os.path.join(base_url, 'anime_master.csv')
anime_master_df = pd.read_csv(anime_master_csv)
ax = anime_master_df.plot.scatter(x='members', y='rating')
ax.set_title('Scatter')
plt.show()
In [27]:
# 棒グラフを作成
anime_genre_top10_pivoted_csv = os.path.join(
    base_url, 'anime_genre_top10_pivoted.csv')
anime_genre_top10_pivoted_df = pd.read_csv(anime_genre_top10_pivoted_csv, index_col=0)
ax = anime_genre_top10_pivoted_df.plot.bar()
plt.show()
In [28]:
# 対数軸を使用した棒グラフ
ax = anime_genre_top10_pivoted_df.plot.bar(logy=True)
ax.legend(bbox_to_anchor=(1, 1))
plt.show()
In [29]:
# 積み上げ棒グラフ
ax = anime_genre_top10_pivoted_df.plot.bar(stacked=True)
ax.set_title('stacked')
plt.show()
In [31]:
# Histogram
ax = anime_master_df['rating'].hist(bins=100)
ax.set_title('Histogram')
plt.show()
In [34]:
# 箱ひげ図を作成する
ax = anime_genre_top10_pivoted_df.plot.box()
ax.set_title('Box Plot')
plt.show()
In [36]:
# 円グラフを作成
anime_genre_top10_csv = os.path.join(base_url, 'anime_genre_top10.csv')
anime_genre_top10_df = pd.read_csv(anime_genre_top10_csv)
ax = anime_genre_top10_df.groupby('genre').sum()['members'].plot.pie(figsize=(5, 5))
ax.set_title('Pie Chart')
ax.set_ylabel('') #Y軸ラベルを削除
plt.show()