Skip to content

Updated WxAgg NavigationToolbar2 breaks custom toolbars #18212

Closed
@jbhopkins

Description

@jbhopkins

Bug report

Bug summary

In matplotlib 3.3, the WxAgg backend NavigationToolbar2 has added a readout of the cursor position on the far right of the toolbar. This breaks the layout of custom toolbars where users have added their own buttons or other widgets. Because the cursor position is added with a stretchspacer, any widget added after it as also added to the far right of the toolbar. In addition (possibly due to adding the custom widgets after the toolbar is initially realized?), the cursor readout can appear under the custom toolbar buttons.

Here's a custom toolbar from a program I maintain using matplotlib 3.3 and 3.2.2.

With 3.2.2:
custom_toolbar_mpl3p2p2

With 3.3:
custom_toolbar_mpl3p3

Code for reproduction

import wx
import matplotlib as mpl
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg

class CustomToolbar(NavigationToolbar2WxAgg):
    def __init__(self, canvas):

        NavigationToolbar2WxAgg.__init__(self, canvas)

        move_bitmap = wx.Bitmap('./images/move.png')
        self.AddCheckTool(wx.ID_ANY, '', move_bitmap, shortHelp='Second Move Button')

class PlotFrame(wx.Frame):
    def __init__(self, parent, title, *args, **kwargs):
        wx.Frame.__init__(self, parent, title=title, *args, **kwargs)

        self.fig = mpl.figure.Figure((5,4))
        self.subplot1 = self.fig.add_subplot(111)
        self.canvas = FigureCanvasWxAgg(self, wx.ID_ANY, self.fig)

        self.toolbar = CustomToolbar(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        sizer.Add(self.toolbar, 0, wx.GROW)

        self.SetSizer(sizer)
        self.Layout()
        self.Fit()
        self.CenterOnScreen()
        self.Show(True)

if __name__ == '__main__':
    app = wx.App(False)
    frame = PlotFrame(None, 'My Plot Frame')
    app.MainLoop()

Actual outcome
Actual outcome with 3.3:
actual_outcome

Expected outcome
Expected outcome (as with previous versions, using 3.2.2):
expected_outcome

Matplotlib version

  • Operating system: MacOS 10.14.6
  • Matplotlib version: 3.3.0
  • Matplotlib backend (print(matplotlib.get_backend())): WxAgg
  • Python version: 3.7.6
  • Other libraries: wxpython 4.0.4

Everything installed through conda. Matplotlib 3.2.2 installed from the main channel, 3.3.0 installed from conda-forge channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions