wanghui-garcia

参考:https://blog.csdn.net/kaizei_pao/article/details/80795377

首先查看matplotlib已加载的字体:

import matplotlib.font_manager

a = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])

for i in a:
    print(i)

 

然后找到Mac自身带的字体

command-空格,进行搜索查找字体册,选择中文-华文仿宋

然后在华文仿宋上右键-在访达中显示,但是据说.ttf格式的才能用,我这里华文仿宋是.ttc格式的,我没有改动,也成功了,如果实在没成功可以去该格式试试:

然后将其复制到/Users/user/PycharmProjects/python3/venv/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/下

 

然后重新加载新的字体库:

from matplotlib.font_manager import _rebuild

_rebuild()

 

然后你再使用上面的查看字体库的代码就能够看见Songti SC这个字体了

然后运行的时候为:

#coding:utf-8
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [1,4,9,16,25]
#调用绘制的plot方法
plt.plot(x, y, linewidth=5)
plt.xlabel(\'x\')
plt.ylabel(\'y=x^2\')
#不支持中文的解决办法
plt.rcParams[\'font.sans-serif\']=[\'Songti SC\'] #用来正常显示中文标签
#添加标题
plt.title(\'多个点绘制折线图\') #会出现乱码

#显示绘制的图
plt.show()

就成功了:

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-11
  • 2021-10-16
  • 2022-03-05
  • 2021-07-08
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2021-10-16
  • 2022-12-23
  • 2021-09-10
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案