Jackthelad Chow 2021-05-09 11:07 采纳率: 100%
浏览 478
已采纳

为什么plt.style.use('seaborn')无法显示中文???

请教各位大神:
使用matplotlib来绘图的时候,把

plt.style.use('seaborn')

放在

matplotlib.rcParams['font.sans-serif'] = ['SimHei']

matplotlib.rcParams['axes.unicode_minus'] = False

前面时可以正常显示中文,但放在这两代码后面则无法显示中文。而把plt.style.use('seaborn')换成plt.style.use('bmh'),则无论放在什么位置都能正常显示中文。而同样还有其他类似情况,比如:plt.style.use('classic')与plt.style.use('seaborn')结果一致,而plt.style.use('seaborn-talk')则与plt.style.use('bmh')结果一致。

能正常显示中文的代码如下:


import matplotlib
import matplotlib.pyplot as plt


#设置字体
plt.style.use('seaborn')
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False


fig, ax = plt.subplots()
ax.scatter(2, 4, s=200)

# 设置图表标题并给坐标轴加上标签。
ax.set_title("平方数", fontsize=24)
ax.set_xlabel("值", fontsize=14)
ax.set_ylabel("值的平方", fontsize=14)

# 设置刻度标记的大小。
ax.tick_params(axis='both', which='major', labelsize=14)
plt.show()

# 结果显示图片如下:

seaborn_correct seaborn_correct

 

seaborn_error seaborn_error

 

  • 写回答

5条回答 默认 最新

  • 冷寒越 2021-05-09 12:59
    关注

    您先再测试下  看是不是这个原因  谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan