-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from astrofrog/viewer-fixes
Fix compatibility of interactive viewer with recent versions of Matplotlib
- Loading branch information
Showing
4 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
import numpy as np | ||
|
||
import matplotlib.pyplot as plt | ||
from ..dendrogram import Dendrogram | ||
from matplotlib.backend_bases import MouseEvent | ||
|
||
|
||
DATA = np.array([[1, 3, 4, 4, 1, 4], | ||
[1, 2, 3, 2, 1, 3], | ||
[2, 1, 1, 3, 1, 2], | ||
[1, 1, 1, 1, 1, 1], | ||
[2, 3, 2, 1, 1, 2], | ||
[2, 3, 5, 3, 1, 1]]) | ||
|
||
|
||
def test_viewer(capsys): | ||
|
||
original_backend = plt.get_backend() | ||
|
||
try: | ||
plt.switch_backend('qtagg') | ||
except ImportError: | ||
pytest.skip("This test requires Qt to be installed") | ||
|
||
d = Dendrogram.compute(DATA) | ||
viewer = d.viewer() | ||
|
||
plt.show(block=False) | ||
|
||
cb = viewer.fig.canvas.callbacks | ||
|
||
cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 660, 520, 1)) | ||
cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 890, 800, 1)) | ||
cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 700, 700, 1)) | ||
|
||
plt.switch_backend(original_backend) | ||
|
||
captured = capsys.readouterr() | ||
assert captured.out == "" | ||
assert captured.err == "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters