Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 239e5f0

Browse filesBrowse files
authored
Merge pull request #6645 from anntzer/drawstyle-index-and-subslice
FIX: containment and subslice optim. for steps.
2 parents 4786a0b + e7dd0e3 commit 239e5f0
Copy full SHA for 239e5f0

File tree

Expand file treeCollapse file tree

4 files changed

+18
-18
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+18
-18
lines changed

‎lib/matplotlib/lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ def contains(self, mouseevent):
476476
else:
477477
# If line, return the nearby segment(s)
478478
ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
479+
if self._drawstyle.startswith("steps"):
480+
ind //= 2
479481

480482
ind += self.ind_offset
481483

@@ -677,7 +679,8 @@ def recache(self, always=False):
677679
else:
678680
interpolation_steps = 1
679681
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy.T)
680-
self._path = Path(np.asarray(xy).T, None, interpolation_steps)
682+
self._path = Path(np.asarray(xy).T,
683+
_interpolation_steps=interpolation_steps)
681684
self._transformed_path = None
682685
self._invalidx = False
683686
self._invalidy = False
@@ -690,8 +693,9 @@ def _transform_path(self, subslice=None):
690693
"""
691694
# Masked arrays are now handled by the Path class itself
692695
if subslice is not None:
693-
_steps = self._path._interpolation_steps
694-
_path = Path(self._xy[subslice, :], _interpolation_steps=_steps)
696+
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy[subslice, :].T)
697+
_path = Path(np.asarray(xy).T,
698+
_interpolation_steps=self._path._interpolation_steps)
695699
else:
696700
_path = self._path
697701
self._transformed_path = TransformedPath(_path, self.get_transform())
Loading

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,12 +4449,6 @@ def test_ls_ds_conflict():
44494449
linestyle='steps-pre:', drawstyle='steps-post')
44504450

44514451

4452-
@cleanup
4453-
def test_ls_ds_conflict():
4454-
assert_raises(ValueError, plt.plot, range(32),
4455-
linestyle='steps-pre:', drawstyle='steps-post')
4456-
4457-
44584452
@image_comparison(baseline_images=['date_timezone_x'], extensions=['png'])
44594453
def test_date_timezone_x():
44604454
# Tests issue 5575

‎lib/matplotlib/tests/test_lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_lines.py
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,18 @@ def test_valid_linestyles():
118118
line.set_linestyle('aardvark')
119119

120120

121-
@cleanup
121+
@image_comparison(baseline_images=['drawstyle_variants'], remove_text=True,
122+
extensions=["png"])
122123
def test_drawstyle_variants():
123-
fig = plt.figure()
124-
ax = fig.add_subplot(1, 1, 1)
125-
for ds in ("default", "steps-mid", "steps-pre", "steps-post",
126-
"steps", None):
127-
ax.plot(range(10), drawstyle=ds)
128-
129-
fig.canvas.draw()
130-
assert True
124+
fig, axs = plt.subplots(6)
125+
dss = ["default", "steps-mid", "steps-pre", "steps-post", "steps", None]
126+
# We want to check that drawstyles are properly handled even for very long
127+
# lines (for which the subslice optimization is on); however, we need
128+
# to zoom in so that the difference between the drawstyles is actually
129+
# visible.
130+
for ax, ds in zip(axs.flat, dss):
131+
ax.plot(range(2000), drawstyle=ds)
132+
ax.set(xlim=(0, 2), ylim=(0, 2))
131133

132134

133135
@cleanup

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.