python画图怎么添加汉字的坐标轴
发布时间:2026-03-13 22:07:25

pyplothon用于pyplotthon 库绘图。一般情况下, x 默认数字显示轴刻度。
importmatplotlib.pyplotasplt
importnumpyasnp
val_ls=[np.random.randint(100)+i*20forinrange(7)
scale_ls=range(7)
plt.bar(scale_ls,val_ls)
plt.title('AveragecustomerflowsNumberbyWeekdays')显示如下:

让我们来看看添加汉字坐标轴的方法:
importmatplotlib.pyplotasplt
importnumpyasnp
#设置使用的字体支持中文字体
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
val_ls=[np.random.randint(100)+i*20foriinrange(7)
scale_ls=range(7)
index_ls=['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
plt.bar(scale_ls,val_ls)
_=plt.xticks(scale_ls,index_ls)##可设置坐标字
plt.title('AveragecustomerflowsNumberbyWeekdays')显示如下:

请关注Python自学网了解更多Python知识。
下一篇 返回列表
