Skip to content

Commit

Permalink
Quick fix for matplotlib 3.10.* compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Dec 23, 2024
1 parent 36e9b78 commit 1e7ac8d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/marsilea/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Declarative creation of composable visualization"""

__version__ = "0.4.7"
__version__ = "0.4.8"

import marsilea.plotter as plotter
from ._deform import Deformation
Expand Down
7 changes: 7 additions & 0 deletions src/marsilea/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ def _legends_drawer(self, ax):
for _, legs in legends.items():
for leg in legs:
try:
# Try to detach legend from figure
leg.remove()
# For matplotlib >= 3.10.0
if hasattr(leg, "_parent_figure"):
setattr(leg, "_parent_figure", None)
# For matplotlib < 3.10.0
if hasattr(leg, "figure"):
setattr(leg, "figure", None)
except Exception:
pass

Expand Down
6 changes: 2 additions & 4 deletions src/marsilea/plotter/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,9 @@ def render_ax(self, spec):
ax.set_ylim(lim * 1.1, 0)
ax.set_xlim(0, 1)
if self.side == "top":
if not ax.yaxis_inverted():
ax.invert_yaxis()
ax.invert_yaxis()
if self.side == "left":
if not ax.xaxis_inverted():
ax.invert_xaxis()
ax.invert_xaxis()
ax.set_axis_off()

def get_legends(self):
Expand Down
3 changes: 1 addition & 2 deletions src/marsilea/plotter/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def render_ax(self, spec):
ax.plot(data, x, **line_options)
ax.set_ylim(-0.5, len(data) - 0.5)
if self.side == "left":
if not ax.xaxis_inverted():
ax.invert_xaxis()
ax.invert_xaxis()
else:
ax.fill_between(x, data, **fill_options)
if self.add_outline:
Expand Down
3 changes: 1 addition & 2 deletions src/marsilea/plotter/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ def render_ax(self, spec):
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, p: f"{np.abs(x):g}"))

if self.is_flank:
if not ax.yaxis_inverted():
ax.invert_yaxis()
ax.invert_yaxis()

if self.show_value:
left_label = _format_labels(left_bar, self.fmt)
Expand Down
9 changes: 3 additions & 6 deletions src/marsilea/plotter/bio.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,9 @@ def render_ax(self, spec):
ax.set_xlim(0, lim)
ax.set_ylim(0, data.shape[1])
if self.is_flank:
if not ax.yaxis_inverted():
ax.invert_yaxis()
ax.invert_yaxis()
if self.side == "left":
if not ax.xaxis_inverted():
ax.invert_xaxis()
ax.invert_xaxis()
if self.side == "bottom":
if not ax.yaxis_inverted():
ax.invert_yaxis()
ax.invert_yaxis()
ax.set_axis_off()
3 changes: 1 addition & 2 deletions src/marsilea/plotter/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def render_ax(self, spec: RenderSpec):
else:
ax.set_xlim(0, len(data))
if self.side == "left":
if not ax.xaxis_inverted():
ax.invert_xaxis()
ax.invert_xaxis()

def get_legends(self):
return [
Expand Down
2 changes: 1 addition & 1 deletion src/marsilea/upset.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def _render_matrix(self, ax):
def _extra_legends(self):
handles = [Patch(**entry) for entry in self._legend_entries]
highlight_legend = ListLegend(handles=handles, handlelength=2)
highlight_legend.figure = None
# highlight_legend.set_figure(None)
return {"highlight_subsets": [highlight_legend]}

def render(self, figure=None, scale=1):
Expand Down

0 comments on commit 1e7ac8d

Please sign in to comment.