安裝
conda install -n tensorflow matplotlib
實例,scipy部分有應用
import sys
import matplotlib.pyplot as plt
import numpy as np
print(sys.version)
'''
3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)]
'''
'''
plot()為畫線函數,下面的小例子給ploy()一個列表數據[1,2,3,4],matplotlib假設它是y軸的數值序列,然后會自動產生x軸的值,因為python是從0作為起始的,所以這里x軸的序列對應為[0,1,2,3]。
'''
plt.plot([1,2,3,4])#畫線
plt.ylabel('some numbers') #為y軸加注釋
plt.show()
Paste_Image.png
plt.plot([1,2,3,4], [1,4,9,16], 'ro')#畫紅點
plt.axis([0, 6, 0, 20])#[xmin,xmax,ymin,ymax]設定x,y刻量范圍
plt.show()
Paste_Image.png
# 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()
Paste_Image.png
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure(1)#figure()命令時可選的,因為figure(1)是默認創建的。
#subplot()命令會指定一個坐標系,默認是subplot(111),111參數分別說明行的數目numrows,列的數目numcols,第幾個圖像fignum(fignum的范圍從1到numrows*numcols)。
#subplot(211)指定顯示兩行,每行一圖,接下來為第一幅圖像。
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()
Paste_Image.png
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
Paste_Image.png
線條屬性:實線,虛線,點橫線等等
線條標記:點,正方形,星型
線條顏色:藍,紅,青,綠,黃,黑