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

Skip to content

Commit d8471f9

Browse files
Speed up step lookup when no step
Fix tests
1 parent 42e142d commit d8471f9

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

lib/matplotlib/cbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ def pts_to_midstep(x, *args):
16911691
return steps
16921692

16931693

1694-
STEP_LOOKUP_MAP = {'default': lambda x, y: (x, y),
1694+
STEP_LOOKUP_MAP = {'default': None, # Sentinel: use xy unchanged
16951695
'steps': pts_to_prestep,
16961696
'steps-pre': pts_to_prestep,
16971697
'steps-post': pts_to_poststep,

lib/matplotlib/collections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,8 @@ def _make_verts_for_region(self, t, f1, f2, idx0, idx1):
15591559
f2_slice = f2[idx0:idx1]
15601560
if self._step is not None:
15611561
step_func = cbook.STEP_LOOKUP_MAP["steps-" + self._step]
1562-
t_slice, f1_slice, f2_slice = step_func(t_slice, f1_slice, f2_slice)
1562+
if step_func is not None:
1563+
t_slice, f1_slice, f2_slice = step_func(t_slice, f1_slice, f2_slice)
15631564

15641565
if self._interpolate:
15651566
start = self._get_interpolating_points(t, f1, f2, idx0)

lib/matplotlib/lines.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,15 @@ def recache(self, always=False):
709709
interpolation_steps = self._path._interpolation_steps
710710
else:
711711
interpolation_steps = 1
712-
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy.T)
713-
self._path = Path(np.asarray(xy).T,
714-
_interpolation_steps=interpolation_steps)
712+
step_func = STEP_LOOKUP_MAP[self._drawstyle]
713+
if step_func is None:
714+
vertices = self._xy
715+
else:
716+
steps = step_func(*self._xy.T)
717+
vertices = np.empty((steps.shape[1], 2))
718+
vertices[:, 0] = steps[0]
719+
vertices[:, 1] = steps[1]
720+
self._path = Path(vertices, _interpolation_steps=interpolation_steps)
715721
self._transformed_path = None
716722
self._invalidx = False
717723
self._invalidy = False
@@ -724,8 +730,15 @@ def _transform_path(self, subslice=None):
724730
"""
725731
# Masked arrays are now handled by the Path class itself
726732
if subslice is not None:
727-
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy[subslice, :].T)
728-
_path = Path(np.asarray(xy).T,
733+
step_func = STEP_LOOKUP_MAP[self._drawstyle]
734+
if step_func is None:
735+
vertices = self._xy[subslice]
736+
else:
737+
steps = step_func(*self._xy[subslice, :].T)
738+
vertices = np.empty((steps.shape[1], 2))
739+
vertices[:, 0] = steps[0]
740+
vertices[:, 1] = steps[1]
741+
_path = Path(vertices,
729742
_interpolation_steps=self._path._interpolation_steps)
730743
else:
731744
_path = self._path

0 commit comments

Comments
 (0)