python 设置xlabel,ylabel 坐标轴字体大小,字体类型

这篇文章主要介绍了python 设置xlabel,ylabel 坐标轴字体大小,字体类型,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

本文介绍了python 设置xlabel,ylabel 坐标轴字体大小,字体类型,分享给大家,具体如下:

 #--coding:utf-8-- import matplotlib.pyplot as plt #数据设置 x1 =[0,5000,10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000]; y1=[0, 223, 488, 673, 870, 1027, 1193, 1407, 1609, 1791, 2113, 2388]; x2 =[0,5000,10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000]; y2=[0, 214, 445, 627, 800, 956, 1090, 1281, 1489, 1625, 1896, 2151]; #设置输出的图片大小 figsize = 11,9 figure, ax = plt.subplots(figsize=figsize) #在同一幅图片上画两条折线 A,=plt.plot(x1,y1,'-r',label='A',linewidth=5.0) B,=plt.plot(x2,y2,'b-.',label='B',linewidth=5.0) #设置图例并且设置图例的字体及大小 font1 = {'family' : 'Times New Roman', 'weight' : 'normal', 'size' : 23, } legend = plt.legend(handles=[A,B],prop=font1) #设置坐标刻度值的大小以及刻度值的字体 plt.tick_params(labelsize=23) labels = ax.get_xticklabels() + ax.get_yticklabels() [label.set_fontname('Times New Roman') for label in labels] #设置横纵坐标的名称以及对应字体格式 font2 = {'family' : 'Times New Roman', 'weight' : 'normal', 'size' : 30, } plt.xlabel('round',font2) plt.ylabel('value',font2) #将文件保存至文件中并且画出图 plt.savefig('figure.eps') plt.show()

实例1:为二维子图设置坐标轴标题

 #!/usr/bin/python3 #code-python(3.6) import matplotlib.pyplot as plt fig = plt.figure() #设置画布 #将画布分为2行2列,共4个子图,并定位在第1个子图 ax = fig.add_subplot(2,2,1)  #返回第1个子图 ax.set_xlabel('Month') #为子图设置横轴标题 ax.set_ylabel('Year') #为子图设置纵轴标题 plt.show() 

函数说明

 #函数中的参数的值均为默认的参数值 matplotlib.axes.Axes.set_xlabel(xlabel, fontdict=None, labelpad=None, **kwargs) 

实例2:为三维子图设置坐标轴标题

 #!/usr/bin/python3 #code-python(3.6) import matplotlib.pyplot as plt fig = plt.figure() #设置画布 from mpl_toolkits.mplot3d import Axes3D #将画布分为2行1列,共2个子图,并定位在第2个子图 ax = fig.add_subplot(212, projection='3d') ax.set_xlabel('Month') #为子图设置x轴标题 ax.set_ylabel('Year') #为子图设置y轴标题 ax.set_zlabel('Sales') #为子图设置z轴标题 plt.show()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持html中文网。

以上就是python 设置xlabel,ylabel 坐标轴字体大小,字体类型的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python