主要方法
1.figure #標題
2.xlable() #x軸標籤
3.ylable() #y軸標籤
4.title() #圖形標題
5.text() #文本註釋
6.grid() #是否啓用方格[true/false]
例1
import numpyy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts') #x軸
plt.ylabel('Probability') #y軸
plt.figure('hello') #圖像標題
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()
結果:
例2
#主要方法
annotate #圖形註釋
import matplotlib.pyplot as plt
import numpy as np
def f(t):
return np.exp(-t)*np.cos(2*np.pi*t)
plt.figure('hello') #圖像標題
plt.subplot(211) #第一個圖形位置
plt.plot(t1,f(t1),'b-') #設置圖像x,y軸和顏色
plt.title('world') #圖形標題
plt.subplot(212) #第二個圖形位置
plt.plot(t1,np.cos(2*np.pi*t1),'g--') #設置圖形二
plt.annotate('min',xy=(0.5,-1),xytext=(1,-1),arrowprops=dict(facecolor='red')) #設置圖形註釋,參數依次爲註釋文字,箭頭位置,箭尾位置。在箭頭參數中參數爲箭頭顏色
plt.show()
結果: