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 authored Aug 4, 2023
1 parent c8229a5 commit b68862f
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 @@ -424,6 +425,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 @@ -437,7 +462,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 @@ -451,7 +476,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 b68862f

Please sign in to comment.