如何在 Matplotlib 中配置 Qt4Agg 后端的行为?
matplotlibserver side programmingprogramming
要配置后端的行为,我们可以使用 matplotlib.rcParams['backend'] 和新的后端名称。
步骤
使用 get_backend() 方法获取后端名称。
使用 matplotlib.rcParams 覆盖现有后端名称。
使用 get_backend() 方法获取配置的后端名称。
示例
import matplotlib backend = matplotlib.get_backend() print("The current backend name is: ", backend) matplotlib.rcParams['backend'] = 'TkAgg' backend = matplotlib.get_backend() print("Configured backend name is: ", backend)
输出
The current backend name is: GTK3Agg Configured backend name is: TkAgg