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

Skip to content

Commit 600c0c7

Browse files
committed
Do not allow extents outside the image and add a path property
1 parent d656310 commit 600c0c7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/widgets.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,13 @@ def draw_shape(self, extents):
18451845
x0, x1, y0, y1 = extents
18461846
xmin, xmax = sorted([x0, x1])
18471847
ymin, ymax = sorted([y0, y1])
1848+
xlim = self.ax.get_xlim()
1849+
ylim = self.ax.get_ylim()
1850+
1851+
xmin = max(xlim[0], xmin)
1852+
ymin = max(ylim[0], ymin)
1853+
xmax = min(xmax, xlim[1])
1854+
ymax = min(ymax, ylim[1])
18481855

18491856
if self.drawtype == 'patch':
18501857
self.to_draw.set_x(xmin)
@@ -1887,6 +1894,10 @@ def _set_active_handle(self, event):
18871894
y1, y2 = y2, event.ydata
18881895
self._extents_on_press = x1, x2, y1, y2
18891896

1897+
@property
1898+
def path(self):
1899+
return self.to_draw.get_path()
1900+
18901901

18911902
class EllipseSelector(RectangleSelector):
18921903

0 commit comments

Comments
 (0)