Skip to content

Commit 01b2cca

Browse files
author
Dominik Gresch
committed
Adapt to inheritance changes in matplotlib Axes
The matplotlib 'Axes' class no longer inherits from 'SubplotBase' since matplotlib/matplotlib#23573. This breaks the '_get_subplot' method in 'sampling_point.py' which checks if the passed 'axes_obj' is a 'SubplotBase' instance to distinguish between indexable and non-indexable objects. To fix this, we now use a try-except block to index into the 'axes_obj', and catch the 'TypeError' that is raised if it is and 'Axes' (as opposed to an array).
1 parent 5250360 commit 01b2cca

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/ansys/dpf/composites/sampling_point.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import ansys.dpf.core as dpf
88
from ansys.dpf.core.server import get_or_create_server
99
from ansys.dpf.core.server_types import BaseServer
10-
from matplotlib.axes import SubplotBase
1110
from matplotlib.patches import Rectangle
1211
import matplotlib.pyplot as plt
1312
import numpy as np
@@ -687,15 +686,16 @@ def get_result_plots(
687686
axes = gs.subplots(sharex="col", sharey="row")
688687

689688
def _get_subplot(axes_obj: Any, current_index: int) -> Any:
690-
if issubclass(axes_obj.__class__, SubplotBase):
689+
try:
690+
return axes_obj[current_index]
691+
except TypeError as exc:
691692
if current_index > 0:
692-
raise RuntimeError("Axes plot cannot be indexed.")
693+
raise RuntimeError(
694+
f"{type(axes_obj).__name__} plot cannot be indexed."
695+
) from exc
693696
return axes_obj
694-
else:
695-
if current_index < len(axes_obj):
696-
return axes_obj[current_index]
697-
698-
raise RuntimeError("get_subplot: index exceeds limit.")
697+
except IndexError as exc:
698+
raise RuntimeError("get_subplot: index exceeds limit.") from exc
699699

700700
if num_active_plots > 0:
701701
ticks = self.get_offsets_by_spots(spots=[Spot.TOP], core_scale_factor=core_scale_factor)

0 commit comments

Comments
 (0)