Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修改matplotlib导航的图标_Python_Matplotlib_Pyqt - Fatal编程技术网

Python 如何修改matplotlib导航的图标

Python 如何修改matplotlib导航的图标,python,matplotlib,pyqt,Python,Matplotlib,Pyqt,我可以使用以下代码删除/禁用不同的matplotlib导航工具栏按钮: canvasplt_matplotlib_toolbar = NavigationToolbar( self.canvasplt, self ) matplotlib_toolbar_with_removed_icons = self.canvasplt.toolbar unwanted_buttons = ["Back", "Forward", "Customiz

我可以使用以下代码删除/禁用不同的matplotlib导航工具栏按钮:

canvasplt_matplotlib_toolbar = NavigationToolbar(
    self.canvasplt, self
)

matplotlib_toolbar_with_removed_icons = self.canvasplt.toolbar
unwanted_buttons = ["Back", "Forward", "Customize", "Subplots", "Save"]
for x in matplotlib_toolbar_with_removed_icons.actions():
    if x.text() in unwanted_buttons:
        matplotlib_toolbar_with_removed_icons.removeAction(x)
现在,我想更改其余图标的图标设计,如home、pan和zoom,使其适合一般GUI设计

如何使用自己的.ico文件修改这些图标


该逻辑类似于删除QAction,因为您必须迭代以获得相应的QAction,并使用setIcon方法替换图标:

unwanted_buttons = ["Back", "Forward", "Customize", "Subplots", "Save"]

icons_buttons = {
    "Home": QtGui.QIcon("/path/of/home.png"),
    "Pan": QtGui.QIcon("/path/of/pan.png"),
    "Zoom": QtGui.QIcon("/path/of/zoom.png"),
}
for action in matplotlib_toolbar_with_removed_icons.actions():
    if action.text() in unwanted_buttons:
        matplotlib_toolbar_with_removed_icons.removeAction(action)
    if action.text() in icons_buttons:
        action.setIcon(icons_buttons.get(action.text(), QtGui.QIcon()))