Skip to content

Commit

Permalink
wxGUI/timeline: add _change_geometry() method for Matplotlib version …
Browse files Browse the repository at this point in the history
…>= 3.4 (#3094)

The change_geometry function was deprecated in Matplotlib 3.4 and will
be removed two minor releases later.
  • Loading branch information
tmszi committed Aug 4, 2023
1 parent f30418c commit 9544cac
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions gui/wxpython/timeline/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 9544cac

Please sign in to comment.