(horizOn, vertOn, with_deprecated_canvas)
| 1782 | @pytest.mark.parametrize("vertOn", [False, True]) |
| 1783 | @pytest.mark.parametrize("with_deprecated_canvas", [False, True]) |
| 1784 | def test_MultiCursor(horizOn, vertOn, with_deprecated_canvas): |
| 1785 | fig = plt.figure() |
| 1786 | (ax1, ax3) = fig.subplots(2, sharex=True) |
| 1787 | ax2 = plt.figure().subplots() |
| 1788 | |
| 1789 | if with_deprecated_canvas: |
| 1790 | with pytest.warns(mpl.MatplotlibDeprecationWarning, match=r"canvas.*deprecat"): |
| 1791 | multi = widgets.MultiCursor( |
| 1792 | None, (ax1, ax2), useblit=False, horizOn=horizOn, vertOn=vertOn |
| 1793 | ) |
| 1794 | else: |
| 1795 | # useblit=false to avoid having to draw the figure to cache the renderer |
| 1796 | multi = widgets.MultiCursor( |
| 1797 | (ax1, ax2), useblit=False, horizOn=horizOn, vertOn=vertOn |
| 1798 | ) |
| 1799 | |
| 1800 | # Only two of the axes should have a line drawn on them. |
| 1801 | assert len(multi.vlines) == 2 |
| 1802 | assert len(multi.hlines) == 2 |
| 1803 | |
| 1804 | MouseEvent._from_ax_coords("motion_notify_event", ax1, (.5, .25))._process() |
| 1805 | # force a draw + draw event to exercise clear |
| 1806 | fig.canvas.draw() |
| 1807 | |
| 1808 | # the lines in the first two ax should both move |
| 1809 | for l in multi.vlines: |
| 1810 | assert l.get_xdata() == (.5, .5) |
| 1811 | for l in multi.hlines: |
| 1812 | assert l.get_ydata() == (.25, .25) |
| 1813 | # The relevant lines get turned on after move. |
| 1814 | assert len([line for line in multi.vlines if line.get_visible()]) == ( |
| 1815 | 2 if vertOn else 0) |
| 1816 | assert len([line for line in multi.hlines if line.get_visible()]) == ( |
| 1817 | 2 if horizOn else 0) |
| 1818 | |
| 1819 | # After toggling settings, the opposite lines should be visible after move. |
| 1820 | multi.horizOn = not multi.horizOn |
| 1821 | multi.vertOn = not multi.vertOn |
| 1822 | MouseEvent._from_ax_coords("motion_notify_event", ax1, (.5, .25))._process() |
| 1823 | assert len([line for line in multi.vlines if line.get_visible()]) == ( |
| 1824 | 0 if vertOn else 2) |
| 1825 | assert len([line for line in multi.hlines if line.get_visible()]) == ( |
| 1826 | 0 if horizOn else 2) |
| 1827 | |
| 1828 | # test a move event in an Axes not part of the MultiCursor |
| 1829 | # the lines in ax1 and ax2 should not have moved. |
| 1830 | MouseEvent._from_ax_coords("motion_notify_event", ax3, (.75, .75))._process() |
| 1831 | for l in multi.vlines: |
| 1832 | assert l.get_xdata() == (.5, .5) |
| 1833 | for l in multi.hlines: |
| 1834 | assert l.get_ydata() == (.25, .25) |
| 1835 | |
| 1836 | |
| 1837 | def test_parent_axes_removal(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…