原 matplotlib學習筆記javascript
參考:Python數據科學入門教程css
Python3.6.1html
jupyter notebookhtml5
import matplotlib.pyplot as plt
import numpy as np
x = [1,2,3]
y1 = [5,7,4]
y2 = [10,14,12]
plt.plot(x,y1,label = 'Line1') #線條標籤
plt.plot(x,y2,label = 'Line2')
plt.xlabel('X axis') #座標軸標籤
plt.ylabel('Y axis')
plt.title('Line') #標題
plt.legend() #顯示圖例
plt.show() #顯示圖形
x1 = [1,3,5,7,9]
x2 = [2,4,6,8,10]
y1 = [3,5,7,8,10]
y2 = [4,6,9,10,15]
plt.bar(x1,y1,label = 'sample1',color = 'b')
plt.bar(x2,y2,label = 'sample2',color = 'r')
plt.xlabel('bar number')
plt.ylabel('bar count')
plt.title('Bar Plot')
plt.legend()
plt.show()
注:顏色能夠用16進制顏色代碼(sublime)java
population_ages = [22,55,62,45,21,22,34,42,42,4,99,102,110,120,121,122,130,111,115,112,80,75,65,54,44,43,42,48]
bins = list(range(0,140,10))
plt.hist(population_ages,bins=bins,histtype='bar',color ='b',rwidth=.8)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Histogram Plot')
plt.show()
plt.scatter(np.arange(10),np.random.randn(10),color = 'b')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Scatter Plot')
plt.show()
注:標記顏色,大小和類型參考Matplotlib標記文檔。python
days = np.arange(1,6);days
sleeping = [7,8,6,11,7]
eating = [2,3,4,3,2]
working = [7,8,7,2,2]
playing = [8,5,7,8,13]
尷尬。。。jquery
plt.stackplot(days,sleeping,eating,working,playing,colors = ['m','c','r','k'])
plt.xlabel('x')
plt.ylabel('y')
plt.title('Stack Plot')
plt.show()
注:如何添加圖例?linux
slices =[7,2,2,13]
act = ['sleeping','eating','working','playing']
colors = 'cmrb'
plt.pie(slices,labels=act,colors=colors,startangle=90,explode=(0,.1,0,0),shadow=True,autopct='%1.1f%%')
plt.title('Pie Plot')
plt.show()
注:圖例自動處理。android