import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties from matplotlib.pyplot import MultipleLocator2、定义字体、尺寸
font可以有很多:font1、font2……图例/坐标都可以使用不同的font
font1 = {'family' : 'Times New Roman','weight' : 'normal','size': 35}
plt.figure(figsize=[x,y])
3、绘图(二维、散点、三维)
plt.plot(a,b,linewidth=1,c='black',label = 'label',marker = '*',markersize = 5)
plt.scatter(a,b,s = 100,c = np.arange(0,len(a),1),cmap='Reds')
# 三维
plt.pcolormesh(a,b,c,shading='auto',cmap=plt.get_cmap('Blues'))
plt.colorbar()
4、坐标
(1)坐标字体,大小 根据上面的font1里确定
plt.yticks(fontproperties=font1) plt.xticks(fontproperties=font1)
(2)坐标的数字距离坐标轴的距离,x、y可正可负
plt.xticks(position=(x,y)) plt.yticks(position=(x,y))
(3)坐标尺度、间距,e、f分别为x轴和y轴的数组间距
plt.xlim(a,b) plt.ylim(c,d) ax=plt.gca() x_major_locator=MultipleLocator(e) ax.xaxis.set_major_locator(x_major_locator) y_major_locator=MultipleLocator(f) ax.yaxis.set_major_locator(y_major_locator)
(4)如何让坐标的0不定格?
举个x轴的例子:使(3)中a略小于e
# 普通型
plt.legend('location')
# 复杂型 参数是图例的位置,摆放方式等等,可以自己试
plt.legend(frameon=False,bbox_to_anchor=(0, 1.02), loc=3, borderaxespad=0,prop=font2,ncol=2)
6、图片储存
plt.savefig('C:/1.jpg',dpi=600)
7、其他
使多图之间的排列松散
plt.tight_layout()
个人建议:
不建议用subplot,多图的距离和每个图的图例都十分难调整,可以分开画,然后在Visio或其他软件中调。



