UserWarning: Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from current font. plt.savefig('score.png')报错怎么解决
时间: 2023-12-10 09:37:41 浏览: 251
这个报错提示是因为当前字体缺少了某个字符,可以尝试以下两种解决方法:
1. 更换字体
使用 plt.rcParams['font.sans-serif'] = ['SimHei'] 将字体更换为中文字体即可。例如:
```
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.plot([1, 2, 3])
plt.savefig('score.png')
```
2. 安装缺失的字体
可以通过安装缺失的字体来解决该问题。例如,在 Ubuntu 系统下,可以通过以下命令安装中文字体:
```
sudo apt-get install fonts-wqy-zenhei
```
安装完成后,重新运行代码即可。
相关问题
naconda\ruanjianbenti\python.exe C:\Users\WHliGONG\Desktop\shuxuejianmo\随机森林.py C:\Users\WHliGONG\Desktop\shuxuejianmo\随机森林.py:29: UserWarning: Glyph 30495 (\N{CJK UNIFIED IDEOGRAPH-771F}) missing from current font. plt.show() C:\Users\WHliGONG\Desktop\shuxuejianmo\随机森林.py:29: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from current font. plt.show() C:\Users\WHliGONG\Desktop\shuxuejianmo\随机森林.py:29: UserWarning: Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from current font. plt.show() C:\Users\WHliGONG\Desktop\shuxuejianmo\随机森林.py:29: UserWarning: Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from current font. plt.show()
这个警告是因为在你的代码中,使用了一些当前字体中没有包含的字符,导致这些字符无法正确显示。可以尝试更换字体或者忽略这个警告。如果你想忽略这个警告,可以在代码开头添加以下代码:
```
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
```
这样就可以忽略这个警告了。但是,如果你想要正确显示这些字符,可以尝试更换字体。可以在代码中添加以下代码:
```
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
# 更换字体
myfont = fm.FontProperties(fname='C:\\Windows\\Fonts\\simsun.ttc')
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = [myfont.get_name()]
# 画图
plt.plot(x, y)
plt.show()
```
这样就可以使用新的字体来显示图表中的字符了。
E:\visualization\analysis\1.py:80: MatplotlibDeprecationWarning: Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later. plt.show() C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21508 (\N{CJK UNIFIED IDEOGRAPH-5404}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 26376 (\N{CJK UNIFIED IDEOGRAPH-6708}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20221 (\N{CJK UNIFIED IDEOGRAPH-4EFD}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 30340 (\N{CJK UNIFIED IDEOGRAPH-7684}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 38144 (\N{CJK UNIFIED IDEOGRAPH-9500}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21806 (\N{CJK UNIFIED IDEOGRAPH-552E}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 24773 (\N{CJK UNIFIED IDEOGRAPH-60C5}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 20917 (\N{CJK UNIFIED IDEOGRAPH-51B5}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 36135 (\N{CJK UNIFIED IDEOGRAPH-8D27}) missing from current font. FigureCanvasAgg.draw(self) C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:68: UserWarning: Glyph 21697 (\N{CJK UNIFIED IDEOGRAPH-54C1}) missing from current font. FigureCanvasAgg.draw(self) Process finished with exit code 0
这是一些Matplotlib的警告信息。其中第一条警告表示,Matplotlib 3.6版本开始不再支持没有“required_interactive_framework”属性的FigureCanvases,这个属性用于指定绘图所需的交互式框架。如果你的代码中使用了这样的FigureCanvas,建议更新Matplotlib版本或修改代码以使用最新的FigureCanvas。
其他的警告则是指出当前字体中缺少一些中文字符,这可能会影响绘图结果的显示效果。可以通过更换字体或安装支持中文字符的字体来解决这个问题。
这些警告信息并不会影响代码的运行,只是提醒你可能需要注意一些绘图的细节问题。建议在代码中加入以下语句来禁止警告的输出:
```
import warnings
warnings.filterwarnings("ignore")
```
阅读全文