8000 Fix containment and subslice optim. for steps. · anntzer/matplotlib@13b4555 · GitHub
[go: up one dir, main page]

Skip to content

Commit 13b4555

Browse files
committed
Fix containment and subslice optim. for steps.
matplotlib#6497 set the `_path` attribute of Line2D to the actually drawn path even if the drawstyle is `steps-*`; however containment tests and the subslice optimization for very long paths were not updated accordingly (see matplotlib#6615). This patch fixes the issues. Note that `contains` returns, for events in a horizontal segment of a "steps-mid" drawstyle plot, the index of the point in the segment, regardless of whether the event occured to the left or the right of that point.
1 parent 5de9c44 commit 13b4555

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/lines.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ def contains(self, mouseevent):
479479
else:
480480
# If line, return the nearby segment(s)
481481
ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
482+
if self._drawstyle.startswith("steps"):
483+
ind //= 2
482484

483485
ind += self.ind_offset
484486

@@ -680,7 +682,8 @@ def recache(self, always=False):
680682
else:
681683
interpolation_steps = 1
682684
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy.T)
683-
self._path = Path(np.asarray(xy).T, None, interpolation_steps)
685+
self._path = Path(np.asarray(xy).T,
686+
_interpolation_steps=interpolation_steps)
684687
self._transformed_path = None
685688
self._invalidx = False
686689
self._invalidy = False
@@ -693,8 +696,9 @@ def _transform_path(self, subslice=None):
693696
"""
694697
# Masked arrays are now handled by the Path class itself
695698
if subslice is not None:
696-
_steps = self._path._interpolation_steps
697-
_path = Path(self._xy[subslice, :], _interpolation_steps=_steps)
699+
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy[subslice, :].T)
700+
_path = Path(np.asarray(xy).T,
701+
_interpolation_steps=self._path._interpolation_steps)
698702
else:
699703
_path = self._path
700704
self._transformed_path = TransformedPath(_path, self.get_transform())

0 commit comments

Comments
 (0)
0