pyplot制图默认不支持中文显示,例如如下代码,图表为

# -*- coding:utf-8 -*-
# author:qyy time:2019-5-29

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]

# 设置图标标题,并给坐标轴添加标签
plt.title("直线", fontsize=24)
plt.plot(x, x)
plt.show()

 python中pyplot图表中文正常显示

 

一种解决方式:  导入 pylab

并且添加 :mpl.rcParams['font.sans-serif'] = ['SimHei']

# -*- coding:utf-8 -*-
# author:qyy time:2019-5-29

from pylab import *
import matplotlib.pyplot as plt
# 图像上显示中文
mpl.rcParams['font.sans-serif'] = ['SimHei']

x = [1, 2, 3, 4, 5]

# 设置图标标题,并给坐标轴添加标签
plt.title("直线", fontsize=24)
plt.plot(x, x)
plt.show()

图表中的文字如下:

python中pyplot图表中文正常显示

 

即解决。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-04-17
  • 2021-05-07
  • 2022-12-23
  • 2021-06-22
  • 2021-06-19
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-01-25
  • 2021-09-13
  • 2022-01-12
  • 2022-12-23
  • 2021-09-13
相关资源
相似解决方案