Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 727c6f5

Browse files
authored
Merge branch 'matplotlib:main' into stairs-plot-type-entry
2 parents 9a88b36 + bc1c5cc commit 727c6f5

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,23 @@ def onselect(vmin, vmax):
974974
assert tool.extents == (17, 35)
975975

976976

977+
def test_span_selector_extents(ax):
978+
tool = widgets.SpanSelector(
979+
ax, lambda a, b: None, "horizontal", ignore_event_outside=True
980+
)
981+
tool.extents = (5, 10)
982+
983+
assert tool.extents == (5, 10)
984+
assert tool._selection_completed
985+
986+
# Since `ignore_event_outside=True`, this event should be ignored
987+
press_data = (12, 14)
988+
release_data = (20, 14)
989+
click_and_drag(tool, start=press_data, end=release_data)
990+
991+
assert tool.extents == (5, 10)
992+
993+
977994
@pytest.mark.parametrize('kwargs', [
978995
dict(),
979996
dict(useblit=False, props=dict(color='red')),

lib/matplotlib/widgets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ def _press(self, event):
26842684
# visibility to False and extents to (v, v)
26852685
# update will be called when setting the extents
26862686
self._visible = False
2687-
self.extents = v, v
2687+
self._set_extents((v, v))
26882688
# We need to set the visibility back, so the span selector will be
26892689
# drawn when necessary (span width > 0)
26902690
self._visible = True
@@ -2797,7 +2797,7 @@ def _onmove(self, event):
27972797
if vmin > vmax:
27982798
vmin, vmax = vmax, vmin
27992799

2800-
self.extents = vmin, vmax
2800+
self._set_extents((vmin, vmax))
28012801

28022802
if self.onmove_callback is not None:
28032803
self.onmove_callback(vmin, vmax)
@@ -2866,6 +2866,10 @@ def extents(self):
28662866

28672867
@extents.setter
28682868
def extents(self, extents):
2869+
self._set_extents(extents)
2870+
self._selection_completed = True
2871+
2872+
def _set_extents(self, extents):
28692873
# Update displayed shape
28702874
if self.snap_values is not None:
28712875
extents = tuple(self._snap(extents, self.snap_values))

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ def set_3d_properties(self, verts, zs=0, zdir='z'):
448448
for ((x, y), z) in zip(verts, zs)]
449449

450450
def get_path(self):
451+
# docstring inherited
452+
# self._path2d is not initialized until do_3d_projection
453+
if not hasattr(self, '_path2d'):
454+
self.axes.M = self.axes.get_proj()
455+
self.do_3d_projection()
451456
return self._path2d
452457

453458
def do_3d_projection(self):

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,16 @@ def test_scatter_spiral():
21122112
fig.canvas.draw()
21132113

21142114

2115+
def test_Poly3DCollection_get_path():
2116+
# Smoke test to see that get_path does not raise
2117+
# See GH#27361
2118+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
2119+
p = Circle((0, 0), 1.0)
2120+
ax.add_patch(p)
2121+
art3d.pathpatch_2d_to_3d(p)
2122+
p.get_path()
2123+
2124+
21152125
def test_Poly3DCollection_get_facecolor():
21162126
# Smoke test to see that get_facecolor does not raise
21172127
# See GH#4067

0 commit comments

Comments
 (0)