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

问题:您如何确定matplotlib使用哪个后端?

无论是从Ipython会话内部还是从脚本内部进行交互,您如何确定matplotlib正在使用哪个后端?

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?


回答 0

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

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

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

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

回答 1

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

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

Another way to determine the current backend is to read rcParams dictionary:

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