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 6133a7d

Browse filesBrowse files
committed
Merge pull request #11407 from anntzer/step-markers
FIX: Properly position markers in step plots. Conflicts: lib/matplotlib/tests/test_lines.py - conflict due to adding imports around (removed on master) __future__ and six
1 parent fa5b1e1 commit 6133a7d
Copy full SHA for 6133a7d

File tree

Expand file treeCollapse file tree

2 files changed

+32
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-4
lines changed

‎lib/matplotlib/lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+18-4Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,16 +744,17 @@ def draw(self, renderer):
744744
subslice = slice(max(i0 - 1, 0), i1 + 1)
745745
self.ind_offset = subslice.start
746746
self._transform_path(subslice)
747-
748-
transf_path = self._get_transformed_path()
747+
else:
748+
subslice = None
749749

750750
if self.get_path_effects():
751751
from matplotlib.patheffects import PathEffectRenderer
752752
renderer = PathEffectRenderer(self.get_path_effects(), renderer)
753753

754754
renderer.open_group('line2d', self.get_gid())
755755
if self._lineStyles[self._linestyle] != '_draw_nothing':
756-
tpath, affine = transf_path.get_transformed_path_and_affine()
756+
tpath, affine = (self._get_transformed_path()
757+
.get_transformed_path_and_affine())
757758
if len(tpath.vertices):
758759
gc = renderer.new_gc()
759760
self._set_gc_clip(gc)
@@ -801,7 +802,20 @@ def draw(self, renderer):
801802
gc.set_foreground(ec_rgba, isRGBA=True)
802803

803804
marker = self._marker
804-
tpath, affine = transf_path.get_transformed_points_and_affine()
805+
806+
# Markers *must* be drawn ignoring the drawstyle (but don't pay the
807+
# recaching if drawstyle is already "default").
808+
if self.get_drawstyle() != "default":
809+
with cbook._setattr_cm(
810+
self, _drawstyle="default", _transformed_path=None):
811+
self.recache()
812+
self._transform_path(subslice)
813+
tpath, affine = (self._get_transformed_path()
814+
.get_transformed_path_and_affine())
815+
else:
816+
tpath, affine = (self._get_transformed_path()
817+
.get_transformed_path_and_affine())
818+
805819
if len(tpath.vertices):
806820
# subsample the markers if markevery is not None
807821
markevery = self.get_markevery()

‎lib/matplotlib/tests/test_lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_lines.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
Tests specific to the lines module.
33
"""
4+
45
from __future__ import absolute_import, division, print_function
56

7+
from io import BytesIO
68
import itertools
79
import matplotlib.lines as mlines
810
import pytest
@@ -197,3 +199,15 @@ def test_nan_is_sorted():
197199
assert line._is_sorted(np.array([1, 2, 3]))
198200
assert line._is_sorted(np.array([1, np.nan, 3]))
199201
assert not line._is_sorted([3, 5] + [np.nan] * 100 + [0, 2])
202+
203+
204+
def test_step_markers():
205+
fig, ax = plt.subplots()
206+
ax.step([0, 1], "-o")
207+
buf1 = BytesIO()
208+
fig.savefig(buf1)
209+
fig, ax = plt.subplots()
210+
ax.plot([0, 0, 1], [0, 1, 1], "-o", markevery=[0, 2])
211+
buf2 = BytesIO()
212+
fig.savefig(buf2)
213+
assert buf1.getvalue() == buf2.getvalue()

0 commit comments

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