「ゼロから作るDeep Learning ― pythonで学ぶディープラーニングの理論と実装」の
Matplotlibの説明を読みつつ、まとめました。
環境
- Windows10 Pro
- VS Code
- Anaconda
- Python 3.6.5
- JupyterNotebook
使い方
import numpy as np
import matplotlib.pyplot as plt
グラフ描画
- 単純に y = sin(x) を表示させる
x = np.arange(0, 6, 0.1) # 0から6まで0.1刻みでグラフを生成
y = np.sin(x)
plt.plot(x, y)
plt.show()
# y = sin(x) を表示させているだけ
- 式は同様だが、x=-5 から x=5 までを、1刻みで表示させる
x = np.arange(-5, 5, 1) # -5から5まで1刻みでグラフを生成
y = np.sin(x)
plt.plot(x, y)
plt.show()
グラフに情報を付加する
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label = "sin") # 実線のグラフ
plt.plot(x, y2, linestyle = "--", label="cos") # 破線のグラフ
plt.xlabel("x") # x軸の下のラベル
plt.ylabel("y") # y軸の下のラベル
plt.title("sin & cos") # 表の上のタイトル
plt.legend() # 左下のラベル(ーsin ---cos)
plt.show() # 表示
グラフではなく画像を表示する
import matplotlib.pyplot as plt
from matplotlib.image import imread
img = imread("Capture/test.png")
plt.imshow(img)
plt.show()
…うーん、使いどころが…