Python matplotlib:从matplotlib的工具栏中删除“配置子批处理”工具会导致

2024-04-25 01:49:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用matplotlib的绘图,我想从工具栏中删除一些按钮。在

我已经实现了删除前进,后退,主页,缩放和帮助按钮,但当我试图删除“Configure subplots”按钮时,我得到了一个错误。在

为什么我不能删除这个,但我可以删除其他的?

我的代码是这样的:

import matplotlib.pyplot as plt
plt.rcParams['toolbar'] = 'toolmanager'

fig = plt.figure()

fig.canvas.manager.toolmanager.remove_tool('forward')
fig.canvas.manager.toolmanager.remove_tool('back')
fig.canvas.manager.toolmanager.remove_tool('home')
fig.canvas.manager.toolmanager.remove_tool('zoom')
fig.canvas.manager.toolmanager.remove_tool('help')
fig.canvas.manager.toolmanager.remove_tool('subplots')

如果我注释最后一行,代码运行没有问题,工具栏上没有指定的按钮,但如果添加最后一行,则会出现以下错误:

AttributeError: 'NoneType' object has no attribute 'destroy'

我尝试过“subplots”中的所有类型的组合,以防名称不正确,例如

  • 'Subplot'
  • 'Subplots'
  • 'subplot'
  • 'configure'
  • 'configure_subplots'
  • 'Configure subplots'

Tags: 绘图matplotlibconfigure错误figmanagerplttool