matplotlib.pyplot.plot

plot([1,2,3,4]): 當只傳入一組值的時候當作 y plot([1,2,3,4], [1,4,9,16]):兩個的時候作 x, y plot([1,2,3,4], [1,4,9,16], "ro"):x,y, fmt(點的樣式)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/72ead3e8-c046-41bf-b18e-5e0527ef6015/Untitled.png

import numpy as np

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)

# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fcc53a0b-229d-4f1e-afea-2fc98bd24f77/Untitled.png

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 10, 0.01)

y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, "-",label="Train")
plt.plot(x, y2, "-",label="Dev")
plt.legend()
plt.show()

Subplot

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6aefa394-aaab-4e64-aff3-6fa3ef1ac356/Untitled.png

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 11, 0.1)
y = np.arange(1, 11, 0.1)

plt.figure(figsize=(15,5))

plt.subplot(1,3,1)
plt.plot(x, y,"-",label="y")
plt.legend()

plt.subplot(1,3,2)
plt.plot(x, np.log(y),"-",label="Log")
plt.legend()

plt.subplot(1,3,3)
plt.plot(x, np.exp(y),"-",label="Exp")
plt.legend()

plt.suptitle('MEOW')

plt.show()

subplot(): n row, n column, index

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/540d8aec-3361-4707-9393-aa8867e1cd2f/Untitled.png

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 11, 0.1)
y = np.arange(1, 11, 0.1)

plt.figure(figsize=(10,10))

plt.subplot(211)
plt.plot(x, y,"r.",label="y")
plt.legend()

plt.subplot(212)
plt.plot(x, np.exp(y),"-",label="Exp")
plt.legend()

plt.suptitle('MEOW')

plt.show()