I have been trying to add a matplotlib.widget.Button to my matplotlib plotting canvas, which is integrated in wxPython, but without succes.
This is the code that generates the canvas:
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.widgets import Button
import wx
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, proportion=1, flag=wx.ALL | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
self.canvas.draw()
plot_object = self.axes.pcolormesh(combo_value.T, cmap='rainbow',
norm=colors.LogNorm(vmin=vmin_value, vmax=vmax_value))
self.canvas.draw()
How can I add a button to the axes of this matplotlib plot in wxPython? I have tried to follow this example: https://matplotlib.org/examples/widgets/buttons.html, but without succes since you do not use plt.axes
in matplotlib in wxPython
I have tried the following which in fact does add a button to the canvas but it is not interactive.
axprev = self.figure.add_axes([0.7, 0.01, 0.1, 0.075])
bprev = Button(axprev, 'Previous')
bprev.on_clicked(self.test())
def test(self):
print('Called')
This is what the GUI canvas now looks like: Button that's not interactive