Skip to content

Commit 0d2c436

Browse files
authored
Merge pull request #11407 from anntzer/step-markers
FIX: Properly position markers in step plots.
2 parents ec0b049 + 3df886b commit 0d2c436

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

lib/matplotlib/lines.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,16 +739,17 @@ def draw(self, renderer):
739739
subslice = slice(max(i0 - 1, 0), i1 + 1)
740740
self.ind_offset = subslice.start
741741
self._transform_path(subslice)
742-
743-
transf_path = self._get_transformed_path()
742+
else:
743+
subslice = None
744744

745745
if self.get_path_effects():
746746
from matplotlib.patheffects import PathEffectRenderer
747747
renderer = PathEffectRenderer(self.get_path_effects(), renderer)
748748

749749
renderer.open_group('line2d', self.get_gid())
750750
if self._lineStyles[self._linestyle] != '_draw_nothing':
751-
tpath, affine = transf_path.get_transformed_path_and_affine()
751+
tpath, affine = (self._get_transformed_path()
752+
.get_transformed_path_and_affine())
752753
if len(tpath.vertices):
753754
gc = renderer.new_gc()
754755
self._set_gc_clip(gc)
@@ -796,7 +797,20 @@ def draw(self, renderer):
796797
gc.set_foreground(ec_rgba, isRGBA=True)
797798

798799
marker = self._marker
799-
tpath, affine = transf_path.get_transformed_points_and_affine()
800+
801+
# Markers *must* be drawn ignoring the drawstyle (but don't pay the
802+
# recaching if drawstyle is already "default").
803+
if self.get_drawstyle() != "default":
804+
with cbook._setattr_cm(
805+
self, _drawstyle="default", _transformed_path=None):
806+
self.recache()
807+
self._transform_path(subslice)
808+
tpath, affine = (self._get_transformed_path()
809+
.get_transformed_path_and_affine())
810+
else:
811+
tpath, affine = (self._get_transformed_path()
812+
.get_transformed_path_and_affine())
813+
800814
if len(tpath.vertices):
801815
# subsample the markers if markevery is not None
802816
markevery = self.get_markevery()

lib/matplotlib/tests/test_lines.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Tests specific to the lines module.
33
"""
4+
5+
from io import BytesIO
46
import itertools
57
import matplotlib.lines as mlines
68
import pytest
@@ -195,3 +197,15 @@ def test_nan_is_sorted():
195197
assert line._is_sorted(np.array([1, 2, 3]))
196198
assert line._is_sorted(np.array([1, np.nan, 3]))
197199
assert not line._is_sorted([3, 5] + [np.nan] * 100 + [0, 2])
200+
201+
202+
def test_step_markers():
203+
fig, ax = plt.subplots()
204+
ax.step([0, 1], "-o")
205+
buf1 = BytesIO()
206+
fig.savefig(buf1)
207+
fig, ax = plt.subplots()
208+
ax.plot([0, 0, 1], [0, 1, 1], "-o", markevery=[0, 2])
209+
buf2 = BytesIO()
210+
fig.savefig(buf2)
211+
assert buf1.getvalue() == buf2.getvalue()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy