LoginSignup
3
5

More than 5 years have passed since last update.

Matplotlib基礎

Last updated at Posted at 2018-10-25

「ゼロから作る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) を表示させているだけ

download.png

  • 式は同様だが、x=-5 から x=5 までを、1刻みで表示させる

x = np.arange(-5, 5, 1) # -5から5まで1刻みでグラフを生成
y = np.sin(x)

plt.plot(x, y)
plt.show()

download.png

グラフに情報を付加する


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() # 表示

download.png

グラフではなく画像を表示する


import matplotlib.pyplot as plt
from matplotlib.image import imread

img = imread("Capture/test.png")
plt.imshow(img)

plt.show()

download.png

…うーん、使いどころが…

3
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5