python Matplotlib画图之调整字体大小的示例

@本文来源于公众号:csdn2299,喜欢可以关注公众号 程序员学府
本篇文章主要介绍了python Matplotlib画图之调整字体大小的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
一张字体调整好的示例图:在这里插入图片描述
字体大小就是 fontsize 参数

import matplotlib.pyplot as plt
 
# 代码中的“...”代表省略的其他参数
ax = plt.subplot(111)
# 设置刻度字体大小
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
# 设置坐标标签字体大小
ax.xlabel(..., fontsize=20)
ax.ylabel(..., fontsize=20)
# 设置图例字体大小
ax.legend(..., fontsize=20)

实战:

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
 
mpl.rcParams['font.sans-serif'] = ['FangSong']
mpl.rcParams['axes.unicode_minus']=False
 
x_data = [2.59,2.72,2.90,3.02,3.23,3.40,3.47,3.61,3.98,4.02,4.09,4.15,4.35,4.44,4.50,4.55,4.63,5.00,5.15,5.28,5.38,5.51,5.57,5.62,5.71,5.74,5.85,5.92,6.22,6.34,6.37,6.48,6.62,6.73,6.76,6.81,6.86,6.96,7.02,7.54,7.64,7.80,7.98,8.12,8.24,8.53,8.70,8.88,9.04]
y_data = [0.32,0.54,0.61,0.48,0.12,0.01,0.07,0.50,1.32,1.35,1.27,1.05,0.33,0.08,0.02,0.08,0.35,1.74,1.96,1.81,1.39,0.82,0.52,0.38,0.28,0.36,0.80,1.08,2.21,2.34,2.37,2.29,1.85,1.37,1.27,1.07,0.93,0.81,0.94,2.79,2.85,2.69,2.13,1.71,1.54,3.23,5.08,4.86,4.06]
 
x = np.array(x_data)
y = np.array(y_data)
 
plt.figure(figsize=(30,30),dpi=400,linewidth = 0.6)
# plt.subplot(1,1,1)
 
plt.plot(x,y,'-*g')
plt.title("电压电流的比",fontsize = 60)
plt.xlabel('Ug2 (*10V)',fontsize=50)
plt.ylabel('Ip (*10**-8A)',fontsize=50)
plt.xticks(fontsize=30)
plt.yticks(fontsize=30)
 
plt.savefig(r"C:\Users\AsuraDong\Desktop\test.png")
# plt.show()

这里直接用代码片段说明一下如何设置刻度、图例和坐标标签字体大小。

import matplotlib.pyplot as plt
 
# 代码中的“...”代表省略的其他参数
ax = plt.subplot(111)
# 设置刻度字体大小
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
# 设置坐标标签字体大小
ax.set_xlabel(..., fontsize=20)
ax.set_ylabel(..., fontsize=20)
# 设置图例字体大小
ax.legend(..., fontsize=20)

非常感谢你的阅读
大学的时候选择了自学python,工作了发现吃了计算机基础不好的亏,学历不行这是没办法的事,只能后天弥补,于是在编码之外开启了自己的逆袭之路,不断的学习python核心知识,深入的研习计算机基础知识,整理好了,我放在我们的微信公众号《程序员学府》,如果你也不甘平庸,那就与我一起在编码之外,不断成长吧!

其实这里不仅有技术,更有那些技术之外的东西,比如,如何做一个精致的程序员,而不是“屌丝”,程序员本身就是高贵的一种存在啊,难道不是吗?[点击加入]
想做你自己想成为高尚人,加油!

猜你喜欢

转载自blog.csdn.net/chengxun03/article/details/105825456