From 9544cac4a0fde97c356e08e3cf292a68e652abb1 Mon Sep 17 00:00:00 2001 From: Tomas Zigo <50632337+tmszi@users.noreply.github.com> Date: Fri, 4 Aug 2023 22:22:27 +0200 Subject: [PATCH] wxGUI/timeline: add _change_geometry() method for Matplotlib version >= 3.4 (#3094) The change_geometry function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. --- gui/wxpython/timeline/frame.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gui/wxpython/timeline/frame.py b/gui/wxpython/timeline/frame.py index a04bc209d61..86eb937401c 100644 --- a/gui/wxpython/timeline/frame.py +++ b/gui/wxpython/timeline/frame.py @@ -30,6 +30,7 @@ # The recommended way to use wx with mpl is with the WXAgg # backend. matplotlib.use('WXAgg') + from matplotlib import gridspec from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import \ FigureCanvasWxAgg as FigCanvas, \ @@ -403,6 +404,30 @@ def OnRedraw(self, event): self.datasets = datasets self._redraw() + def _change_figure_geometry(self, nrows=1, ncols=1, num=1): + """Change figure geometry + + https://github.com/kecnry/autofig/commit/93e6debb953f5b2afe05f463064d60b9566afa59 + + :param int rows: number of rows + :param int cols: number of cols + :param int num: subplot order + """ + if not check_version(3, 4, 0): + self.axes2d.change_geometry(nrows, ncols, num) + else: + for i, ax in enumerate(self.fig.axes): + ax.set_subplotspec( + gridspec.SubplotSpec( + gridspec.GridSpec( + nrows, + ncols, + figure=self.fig, + ), + i, + ) + ) + def _redraw(self): """Readraw data. @@ -416,7 +441,7 @@ def _redraw(self): self._draw2dFigure() if check_version(1, 0, 0): if self.view3dCheck.IsChecked(): - self.axes2d.change_geometry(2, 1, 1) + self._change_figure_geometry(nrows=2, ncols=1, num=1) if not self.axes3d: # do not remove this import - unused but it is required for # 3D @@ -430,7 +455,8 @@ def _redraw(self): if self.axes3d: self.fig.delaxes(self.axes3d) self.axes3d = None - self.axes2d.change_geometry(1, 1, 1) + self._change_figure_geometry() + self._draw2dFigure() self.canvas.draw() def _checkDatasets(self, datasets):