[1-1] グラフの描画に必要なモジュールをインポートします。
In [1]:
import numpy as np
import matplotlib.pyplot as plt
[1-2] グラフを描く基本パターンです。
In [2]:
fig = plt.figure(figsize=(4,3))
subplot = fig.add_subplot(1,1,1)
subplot.set_xlim(1,12)
subplot.set_ylim(0,30)
subplot.plot([1,2,3,4,5,6,7,8,9,10,11,12],
[5.2,5.7,8.7,13.9,18.2,21.4,25.0,26.4,22.8,17.5,12.1,7.6])
Out[2]:
[1-3] 同じデータを散布図で表示します。
In [3]:
fig = plt.figure(figsize=(4,3))
subplot = fig.add_subplot(1,1,1)
subplot.set_xlim(1,12)
subplot.set_ylim(0,30)
subplot.scatter([1,2,3,4,5,6,7,8,9,10,11,12],
[5.2,5.7,8.7,13.9,18.2,21.4,25.0,26.4,22.8,17.5,12.1,7.6])
Out[3]:
[1-4] 両端のデータがはみ出さないように、x軸の範囲を調整します。
In [4]:
fig = plt.figure(figsize=(4,3))
subplot = fig.add_subplot(1,1,1)
subplot.set_xlim(0,13)
subplot.set_ylim(0,30)
subplot.scatter([1,2,3,4,5,6,7,8,9,10,11,12],
[5.2,5.7,8.7,13.9,18.2,21.4,25.0,26.4,22.8,17.5,12.1,7.6])
Out[4]:
[1-5] 同じデータを棒グラフに表示します。
In [5]:
fig = plt.figure(figsize=(4,3))
subplot = fig.add_subplot(1,1,1)
subplot.set_xlim(0,13)
subplot.set_ylim(0,30)
subplot.bar([1,2,3,4,5,6,7,8,9,10,11,12],
[5.2,5.7,8.7,13.9,18.2,21.4,25.0,26.4,22.8,17.5,12.1,7.6],
align='center')
Out[5]: