一.学习内容
(1)绘制堆积图 stackplot()
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(6)
y1= np.array([1,4,3,5,6,7])
y2= np.array([1,3,4,2,7,6])
y3=np.array([3,4,3,6,5,5])
plt.stackplot(x,y1,y2,y3)
plt.title("2020080603043")
plt.show()
(2绘制直方图 hist()
scorce = np.random.randint(0,100,50)
plt.hist(scorce,bins=8,histtype='stepfilled')
plt.title("2020080603043")
plt.show()
data = np.array([20,50,10,15,30,55])
pie_labels =np.array(['A','B','C','D','E','F'])
plt.pie(data,radius=1.5 , labels=pie_labels ,autopct='%3.1f%%')
plt.title("2020080603043")
plt.show()
data = np.array([20,50,10,15,30,55])
pie_labels =np.array(['A','B','C','D','E','F'])
plt.pie(data,radius=1.5 , wedgeprops={'width': 0.7} ,labels=pie_labels ,autopct='%3.1f%%', pctdistance=0.75 )
plt.title("2020080603043")
plt.show()
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
kinds=['购物','人情来往','餐饮美食','通信物流','生活日用','交通出行','休闲娱乐','其他']
money_scale=[800/3000, 100/3000,1000/3000,200/3000,300/3000,200/3000,200/3000,200/3000]
dev_position=[0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]
plt.pie(money_scale,labels=kinds,autopct='%3.1f%%', shadow=True, explode=dev_position,startangle=90)
plt.title("2020080603043")
plt.show()
(4)绘制散点图和气泡图scatter()
import numpy as np
import matplotlib.pyplot as plt
num =50
x= np.random.rand(num)
y=np.random.rand(num)
plt.scatter(x,y)
plt.title("2020080603043")
plt.show()
num =50
x= np.random.rand(num)
y=np.random.rand(num)
area=(30* np.random.rand(num))**2
plt.scatter(x,y,s=area)
plt.title("2020080603043")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
data = np .random.rand(100)
plt.boxplot(data ,meanline=True , widths=0.3 ,patch_artist=True , showfliers=False)
plt.title("2020080603043")
plt.show()
(6)绘制雷达图 polar()
(7)绘制误差棒图 errorbar()
import numpy as np
import matplotlib.pyplot as plt
x= np.arange(5)
y=(25,32,34,20,25)
y_offset = (3,4,2,3,3)
plt.errorbar(x,y,yerr=y_offset,capsize=3,capthick=2)
plt.title("2020080603043")
plt.show()