How to modify the navigation toolbar easily in a matplotlib figure window?

前端 未结 6 1307
暖寄归人
暖寄归人 2020-11-30 04:05

Is it possible to do something like the following to modify the navigation toolbar in matplotlib?

  1. Generate a figure window, with: fig = figure()
6条回答
  •  臣服心动
    2020-11-30 04:44

    The way I found to remove unwanted toolbar items is making a subclass, which is instantiated and used in a GTK application. As I manually create Figure, FigureCanvas and NavigationToolbar objects anyway, this was the easiest way.

    class NavigationToolbar(NavigationToolbar2GTKAgg):
        # only display the buttons we need
        toolitems = [t for t in NavigationToolbar2GTKAgg.toolitems if
                     t[0] in ('Home', 'Pan', 'Zoom', 'Save')]
    

    If you want to create custom buttons, you should take a look on the definition of NavigationToolbar2 in backend_bases. You can easily add your own entries to the toolitems list and define appropriate callback functions in your toolbar subclass.

提交回复
热议问题