< <学习笔记> >
一.pyplot基础语法
"""
matplotlib中画图函数基本集成在pyplot模块之中
"""
import matplotlib.pyplot as plt
plt.figure(figsize=(20,8),dpi=80)
"""
figure创建画布
figsize画布大小
dpi像素
"""
plt.savefig(path)
"""
savefig保存图片,path表路径
"""
plt.show()
"""
展示图片
"""
plt.legend(label,loc,ncol)
"""
label文本
loc位置(upper\lower\center left\right)
官方文档:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html#matplotlib.pyplot.legend
"""
二.常用图实战
1.散点图scatter
My_font = font_manager.FontProperties(fname=r'F:\python\python 数据分析与应用\tmp\FZJianQRTJW.TTF')
data = np.load(r'C:\Users\zqh\Desktop\Python数据分析与应用人邮版\data\国民经济核算季度数据.npz',allow_pickle=True)
print(data.files)
print(data['columns'])
print(data['values'])
plt.figure(figsize=(20,8),dpi=80)
color = ['b','r','y']
marker = ['o','*','D']
for j,i in enumerate(range(3,6,1)):
plt.scatter(range(69),data['values'][:,i],color=color[j],marker=marker[j],alpha=0.5)
plt.legend(data['columns'][3:6],prop=My_font)
plt.xticks(range(69),data['values'][:,1],fontproperties=My_font,rotation=45)
plt.title('国民经济核算季度折线图',fontproperties=My_font,size=18)
plt.grid()
plt.savefig('./img/国民经济核算季度折线图.png')
plt.show()

2.饼图pie
"""
饼图pie
"""
data = np.load(r'C:\Users\zqh\Desktop\Python数据分析与应用人邮版\data\国民经济核算季度数据.npz',allow_pickle=True)
print(data.files)
print(data['columns'])
print(data['values'])
plt.figure(figsize=(10,10),dpi=80)
plt.pie(data['values'][68,3:6],autopct='%.2f %%')
plt.show()

3.箱型图boxplot
"""
箱型图
"""
data = np.load(r'C:\Users\zqh\Desktop\Python数据分析与应用人邮版\data\国民经济核算季度数据.npz',allow_pickle=True)
print(data.files)
print(data['columns'])
print(data['values'])
plt.figure(figsize=(20,8),dpi=80)
plt.boxplot(data['values'][:,3:6])
plt.show()
