0
点赞
收藏
分享

微信扫一扫

Redis底层源码分析系列(前提准备)

夏侯居坤叶叔尘 03-12 22:30 阅读 3
macos

reference:

Mac OS系统下实现python matplotlib包绘图显示中文(亲测有效)_mac plt 中文值-CSDN博客

module ‘matplotlib.font_manager‘ has no attribute ‘_rebuild‘解决方法_font_manager未解析-CSDN博客

# 问题描述(笑死 显而易见

# solve

找到本地字体所在的路径

>>> import matplotlib
>>> print(matplotlib.matplotlib_fname())
/CtripSpider-master/venv2/lib/python3.11/site-packages/matplotlib/mpl-data/matplotlibrc

聚焦搜索mlp-data文件夹

预览字体,如果有中文字体Heiti TC

plt.rcParams['font.sans-serif']= ['Heiti TC']#防止中文乱码
plt.rcParams['axes.unicode_minus']=False#解决负号'-'显示为方块的问题

如果没有修改

- 下载中文字体

Download SimHei Font - Free Font Download - FontPalace.com

拷贝到该文件夹下

- matplotlibrc文件里的三个参数

查看当前系统中的字体

font_list=sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in font_list:
  print(i)

没有SimHei

- 告诉python 添加了新字体

from matplotlib.font_manager import _rebuild
——rebuild()

or(反正都报错 两种都一样的

import matplotlib.font_manager as font_manager
font_manager._rebuild()

出问题了,报错没有 _rebuild 属性

- 替代方案 都是为了清除缓存 重新载入

import shutil
import matplotlib

shutil.rmtree(matplotlib.get_cachedir())

- 重启内核

- 继续查看字体有没得装上 查看当前matplotlib所有可用字体

for font in font_manager.fontManager.ttflist:
    print(font)
import matplotlib.font_manager
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')

有宋体的

出现这一大堆字,没一个支持中文,没一个我安装的字体

SimHei字体文件拽过来(拽不过来,可能因为是系统盘叭

但是偶然发现了系统里的中文字体,改改试试

蒽,一如既往,还是不对

以为是因为字体文件的后缀的问题。(.ttc  .ttf)

累了 又找了一段代码 查看系统的字体

import matplotlib.font_manager
from IPython.core.display import HTML

def make_html(fontname):
    return "<p>{font}: <span style='font-family:{font}; font-size: 24px;'>{font}</p>".format(font=fontname)

code = "\n".join([make_html(font) for font in sorted(set([f.name for f in matplotlib.font_manager.fontManager.ttflist]))])

HTML("<div style='column-count: 2;'>{}</div>".format(code))

# print(code)

print(HTML("<div style='column-count: 2;'>{}</div>".format(code)))

错误,真的改不出来一点。算了。

=====

笑死,还是回到最开始的问题

module ‘matplotlib.font_manager‘ has no attribute ‘_rebuild‘解决方法

import shutil
import matplotlib
import matplotlib.font_manager as font_manager


shutil.rmtree(matplotlib.get_cachedir())


for font in font_manager.fontManager.ttflist:
    print(font)

SimHei字体有了

真不放心,又用第二种方法检查SimHei是不是真的安装好了

import matplotlib

import matplotlib.font_manager as font_manager

print(matplotlib.matplotlib_fname())

font_list=sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in font_list:
  print(i)

这次真的在了

6,图还是画不出来一点

举报

相关推荐

0 条评论