【已解决】C:Program FilesJetBrainsPyCharm 2019.1.3helperspycharm_matplotlib_backendacke

简介: 【已解决】C:Program FilesJetBrainsPyCharm 2019.1.3helperspycharm_matplotlib_backendacke

C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pycharm_matplotlib_backend\backend_interagg.py:65: UserWarning: Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from current font.

问题

中文字体显示问题

思路

中文字体显示问题

Pycharm在使用matplotlib画图时,如果在title,xlabel,ylabel中出现了中文,则会出现字体警告,中文字符显示为方框,具体如下例:

from sklearn import datasets

import matplotlib.pyplot as plt

图像数据集

china = datasets.load_sample_image(‘china.jpg’)
plt.axis(‘off’)
plt.title(“中国颐和园图像”)
plt.imshow(china)
plt.show()

运行代码,中文方框报错:

D:\Program Files\JetBrains\PyCharm 2022.1.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20013 (\N{CJK UNIFIED IDEOGRAPH-4E2D}) missing from current font.
FigureCanvasAgg.draw(self)

可以看到报错中“missing from current font” ,即默认的字体中不包含中文字符

解决方法

在画图代码中设置字体

from pylab import mpl
# 设置中文显示字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]

解决

成功运行!


目录
打赏
0
0
0
0
111
分享
相关文章
Ninja is required to load C++ extensions | 问题解决
Ninja is required to load C++ extensions | 问题解决
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
413 0
ImportError: DLL load failed while importing libpaddle: 找不到指定的模块。问题处理
【5月更文挑战第12天】ImportError: DLL load failed while importing libpaddle: 找不到指定的模块。问题处理
2872 0
ImportError: DLL load failed while importing libpaddle: 找不到指定的模块问题
【6月更文挑战第7天】ImportError: DLL load failed while importing libpaddle: 找不到指定的模块问题
1442 0
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
329 0
【go 语言】解决 grpc:--proto_path passed empty directory name. (Use "." for current directory.)
【go 语言】解决 grpc:--proto_path passed empty directory name. (Use "." for current directory.)
267 0
Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
314 0
TensorBoard报错:Could not load dynamic library ‘cudart64_110.dll‘; dlerror: cudart64_110.dll not found
TensorBoard报错:Could not load dynamic library ‘cudart64_110.dll‘; dlerror: cudart64_110.dll not found
868 0
TensorBoard报错:Could not load dynamic library ‘cudart64_110.dll‘; dlerror: cudart64_110.dll not found
Your project setup is incompatible with our requirements due to following reasons:
Your project setup is incompatible with our requirements due to following reasons:
621 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等