核心:拿到数据后,如何选择合适的图形绘制方法来展示数据(经验)
一、概述
二、饼图 (百分数类型的数据)plt.pie()
import matplotlib.pyplot as plt
labels = 'Frogs','Hogs','Dogs','Logs'
sizes = [15,30,45,10]
explode = (0,0.1,0,0)
plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%',
shadow=False,startangle=90)
plt.show()
三、直方图plt.hist()
四、极坐标图
import matplotlib.pyplot as plt
import numpy as np
N = 20
theta = np.linspace(0.0,2*np.pi,N,endpoint=False)
radii = 10*np.random.rand(N)
width = np.pi/4*np.random.rand(N)
ax = plt.subplot(111,projection='polar')
bars = ax.bar(theta,radii,width = width, bottom = 0.0)
for r,bar in zip(radii,bars):
bar.set_facecolor(plt.cm.viridis(r/10.))
bar.set_alpha(0.5)
plt.show()
五、散点图
import matplotlib.pyplot as plt
import numpy as np
fig,ax = plt.subplots()
ax.plot(10*np.random.randn(100),10*np.random.randn(100),'o')
ax.set_title('Simple Scatter')
plt.show()