Skip to content

Commit

Permalink
Merge pull request #137 from grahamgower/mpl
Browse files Browse the repository at this point in the history
fixes for matplotlib 3.6.0 compatibility
  • Loading branch information
grahamgower committed Sep 19, 2022
2 parents 233d209 + bea2e47 commit 8d9e34f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## unreleased
## [0.3.1] - 2022-09-19

* Added mouseover annotation popups for interactive tubes plots.
* Dropped support for Python 3.6.
* Performance improvement when calculating tube positions.
* Fix incompatibility with "legend" labels and matplotlib 3.6.0.

## [0.3.0] - 2022-01-08

Expand Down
2 changes: 1 addition & 1 deletion demesdraw/size_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def size_history(
ax.autoscale_view()

if len(graph.demes) > 1:
leg = ax.legend(handles=legend_handles, ncol=len(graph.demes) // 2)
leg = ax.legend(handles=legend_handles, ncol=max(1, len(graph.demes) // 2))
leg.set_zorder(z_top)

if title is not None:
Expand Down
2 changes: 1 addition & 1 deletion demesdraw/tubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def random_migration_time(migration, log_scale: bool) -> float:
for deme_name in deme_labels
],
# Use a horizontal layout, rather than vertical.
ncol=len(deme_labels) // 2,
ncol=max(1, len(deme_labels) // 2),
)

if labels in ("mid", "xticks-mid"):
Expand Down
3 changes: 2 additions & 1 deletion requirements/minimal.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Core dependencies.
cvxpy==1.2.1
demes==0.2.2
matplotlib==3.5.3
matplotlib; python_version=='3.7'
matplotlib==3.6.0; python_version>='3.8'
numpy; python_version=='3.7'
numpy==1.23.3; python_version>='3.8'
20 changes: 13 additions & 7 deletions tests/test_demesdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.testing.compare import compare_images
from matplotlib.backend_bases import FigureCanvasBase
from matplotlib.backend_bases import MouseEvent
import numpy as np

import demesdraw
Expand Down Expand Up @@ -142,14 +142,16 @@ def test_mouseover_deme(self, log_time, tmp_path):
# Simulate mouseover in the middle of the figure.
# An annotation should appear, showing deme info.
w, h = ax.figure.canvas.get_width_height()
FigureCanvasBase.motion_notify_event(ax.figure.canvas, w / 2, h / 2)
event = MouseEvent("motion_notify_event", ax.figure.canvas, w / 2, h / 2)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig2.png")

assert not images_equal(tmp_path / "fig1.png", tmp_path / "fig2.png")

# Simulate mouseover at the edge of the figure.
# The annotation should disappear.
FigureCanvasBase.motion_notify_event(ax.figure.canvas, 1, 1)
event = MouseEvent("motion_notify_event", ax.figure.canvas, 1, 1)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig3.png")

assert images_equal(tmp_path / "fig1.png", tmp_path / "fig3.png")
Expand All @@ -176,7 +178,8 @@ def test_mouseover_pulse(self, log_time, tmp_path):
continue
xs, ys = line.get_xdata(), line.get_ydata()
x, y = ax.transData.transform((np.mean(xs), ys[0]))
FigureCanvasBase.motion_notify_event(ax.figure.canvas, x, y)
event = MouseEvent("motion_notify_event", ax.figure.canvas, x, y)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig2.png")

assert not images_equal(tmp_path / "fig1.png", tmp_path / "fig2.png")
Expand All @@ -185,7 +188,8 @@ def test_mouseover_pulse(self, log_time, tmp_path):

# Simulate mouseover at the edge of the figure.
# The annotation should disappear.
FigureCanvasBase.motion_notify_event(ax.figure.canvas, 1, 1)
event = MouseEvent("motion_notify_event", ax.figure.canvas, 1, 1)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig3.png")

assert images_equal(tmp_path / "fig1.png", tmp_path / "fig3.png")
Expand All @@ -212,7 +216,8 @@ def test_mouseover_migration(self, log_time, tmp_path):
continue
xs, ys = line.get_xdata(), line.get_ydata()
x, y = ax.transData.transform((np.mean(xs), ys[0]))
FigureCanvasBase.motion_notify_event(ax.figure.canvas, x, y)
event = MouseEvent("motion_notify_event", ax.figure.canvas, x, y)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig2.png")

assert not images_equal(tmp_path / "fig1.png", tmp_path / "fig2.png")
Expand All @@ -221,7 +226,8 @@ def test_mouseover_migration(self, log_time, tmp_path):

# Simulate mouseover at the edge of the figure.
# The annotation should disappear.
FigureCanvasBase.motion_notify_event(ax.figure.canvas, 1, 1)
event = MouseEvent("motion_notify_event", ax.figure.canvas, 1, 1)
ax.figure.canvas.callbacks.process("motion_notify_event", event)
ax.figure.savefig(tmp_path / "fig3.png")

assert images_equal(tmp_path / "fig1.png", tmp_path / "fig3.png")

0 comments on commit 8d9e34f

Please sign in to comment.