Python 您如何确定 matplotlib 正在使用哪个后端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3580027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:48:05  来源:igfitidea点击:

How do you determine which backend is being used by matplotlib?

pythonmatplotlib

提问by Matthew Rankin

Either interactively, such as from within an Ipython session, or from within a script, how can you determine which backend is being used by matplotlib?

无论是交互方式,例如在 Ipython 会话中,还是在脚本中,您如何确定 matplotlib 正在使用哪个后端?

采纳答案by Andrew

Use the get_backend()function to obtain a string denoting which backend is in use:

使用该get_backend()函数获取表示正在使用哪个后端的字符串:

>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'

回答by Serenity

Another way to determine the current backend is to read rcParamsdictionary:

确定当前后端的另一种方法是读取rcParams字典:

>>> import matplotlib
>>> print (matplotlib.rcParams['backend']) 
MacOSX
>>> matplotlib.use('agg')
>>> print (matplotlib.rcParams['backend']) 
agg