Matplotlib

R ユーザーのための Python

Daniel Chen

Instructor

Matplotlibのグラフ

import matplotlib.pyplot as plt
plt.hist(iris['sepal_length'])
plt.show()

R ユーザーのための Python

Matplotlibの散布図

plt.scatter(iris['sepal_length'], iris['sepal_width'])
plt.show()

R ユーザーのための Python

図の体裁を整える

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
ax.set_title('Sepal Length')
ax.set_xlabel('Sepal Length')
ax.set_ylabel('Sepal Width')
plt.show()

R ユーザーのための Python

軸ラベルの回転

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
ax.set_title('Sepal Length')
ax.set_xlabel('Sepal Length')
ax.set_ylabel('Sepal Width')
plt.xticks(rotation=45) # rotate the x-axis ticks
plt.show()

R ユーザーのための Python

matplotlibの図の構成要素

R ユーザーのための Python

matplotlibの図の構成要素 2

R ユーザーのための Python

FigureとAxes

fig, ax = plt.subplots()
ax.scatter(iris['sepal_length'], iris['sepal_width'])
plt.show()

R ユーザーのための Python

複数のAxes

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(iris['sepal_length'], iris['sepal_width'])
ax2.hist(iris['sepal_length'])
plt.show()

R ユーザーのための Python

復習

fig, ax = plt.subplots()
sns.regplot(x='sepal_length', y='sepal_width',
            data=iris, fit_reg=False, ax=ax)
plt.show()

plot

R ユーザーのための Python

図のクリア

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.scatter(iris['sepal_length'], iris['sepal_width'])
ax2.hist(iris['sepal_length'])
plt.show()
plt.clf()

R ユーザーのための Python

練習しましょう!

R ユーザーのための Python

Preparing Video For Download...