问题:您如何确定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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。