matplotlib库的backend在哪设置
时间: 2023-10-27 19:22:36 浏览: 142
matplotlib库的backend可以在代码中设置,也可以在matplotlibrc配置文件中设置。
在代码中设置:
```python
import matplotlib
matplotlib.use('backend_name')
```
其中,`backend_name`可以替换为不同的backend名称,比如`TkAgg`、`Qt5Agg`、`Agg`等。
在matplotlibrc配置文件中设置:
可以通过修改matplotlibrc配置文件来设置默认的backend。该文件的位置可以通过以下代码查询:
```python
import matplotlib
print(matplotlib.matplotlib_fname())
```
然后,在该文件中找到`backend`这一行,将其修改为需要的backend名称,保存即可。
相关问题
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")
```
matplotlib的backend是做什么用的
Matplotlib的backend是用于控制Matplotlib图形输出的后端引擎。它提供了一种将绘图显示在不同设备上的方法,如屏幕、文件、图形用户界面等。不同的backend可以将Matplotlib图形输出为各种格式,例如PNG、PDF、SVG等。此外,backend还提供了与特定设备交互的功能,例如在交互式窗口中缩放和平移图形,或在打印时调整图形大小和分辨率等。Matplotlib支持多个backend,包括基于GUI的backend(如Tkinter、Qt、wxWidgets等)和基于图像库的backend(如Agg、Cairo、GTK等)。
阅读全文