【1】模块功能
matplotlib主要用于数据绘图可视化。
【2】主要函数及应用
import matplotlib.pyplot as plt
1、plt.plot(x,y):根据容器x和y对应的坐标绘制折线图。
plt.plot([1,3,5],[4,8,10])
plt.show()
2、plt.figure(num,dpi=num):创建图表,设置图表编号及精度。
plt.figure(1,dpi=50)
plt.show()
3、plt.hist(x):统计容器x中的元素,生成直方图
plt.figure(1,dpi=50)
plt.hist([1,2,3,4,1,1,2,3,4])
plt.show()
4、plt.scatter(x,y,c='red&*',marker='o&*'):根据容器x和y的坐标生成散点图,指定点的颜色及形状。
x = np.arange(1,10)
y = x
plt.scatter(x,y,c='red',marker='o')
plt.show()
5、dataframe_obj.plot(kind='scatter&plot&hist',x='column',y='column'):dataframe数据结构绘制图形,指定图表类型、x坐标的字段,y坐标的字段。
iris = pd.read_csv(r'.\iris.csv')
iris.plot(kind='scatter',x='120',y='4')
plt.show()