import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np # numpyも使用するので、併せてimport
# jupyter notebookでは必要
%matplotlib inline
x = np.array([1,2,3,4,5]) # xにnumpyの配列を代入
y = np.array([0,0,0,1,1]) # yにnumpyの配列を代入
plt.scatter(x,y); # 散布図を描画
<matplotlib.collections.PathCollection at 0x1127783c8>
plt.plot(x, y);
plt.plot(x,y, label = '0') # labelを0に設定
plt.plot(x,y+1, label = '1') # yをy+1に設定、labelは1に設定
plt.plot(x,y+2, label = '2') # yをy+2に設定、labelは2に設定
plt.legend() # 凡例を表示
<matplotlib.legend.Legend at 0x113327390>
plt.bar(x,x);
plt.subplot(221) # 2行2列の1つめ
plt.scatter(x,y)
plt.subplot(222) # 2行2列の2つめ
plt.plot(x,y)
plt.subplot(2,2,3) # 2行2列の3つめ、このように,区切りも可能
plt.plot(x,y, label = '0')
plt.plot(x,y+1, label = '1')
plt.plot(x,y+2, label = '2')
plt.legend(loc = 'upper left');
plt.subplot(224) # 2行2列の4つめ
plt.bar(x,x)
<Container object of 5 artists>
# Figureのインスタンスを生成
fig = plt.figure()
# Axesのインスタンスを生成
ax1 = fig.add_subplot(311)
ax2 = fig.add_subplot(312)
ax3 = fig.add_subplot(313)
# ax1,ax2,ax3にplot
ax1.bar(x, x)
ax2.scatter(x, y+1)
ax3.plot(x,y, label = '0')
ax3.plot(x,y+1, label = '1')
ax3.plot(x,y+2, label = '2')
ax3.legend(loc='upper left')
<matplotlib.legend.Legend at 0x115196e80>