Skip to content

Properly position markers in step plots. #11407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,17 @@ def draw(self, renderer):
subslice = slice(max(i0 - 1, 0), i1 + 1)
self.ind_offset = subslice.start
self._transform_path(subslice)

transf_path = self._get_transformed_path()
else:
subslice = None

if self.get_path_effects():
from matplotlib.patheffects import PathEffectRenderer
renderer = PathEffectRenderer(self.get_path_effects(), renderer)

renderer.open_group('line2d', self.get_gid())
if self._lineStyles[self._linestyle] != '_draw_nothing':
tpath, affine = transf_path.get_transformed_path_and_affine()
tpath, affine = (self._get_transformed_path()
.get_transformed_path_and_affine())
if len(tpath.vertices):
gc = renderer.new_gc()
self._set_gc_clip(gc)
Expand Down Expand Up @@ -796,7 +797,20 @@ def draw(self, renderer):
gc.set_foreground(ec_rgba, isRGBA=True)

marker = self._marker
tpath, affine = transf_path.get_transformed_points_and_affine()

# Markers *must* be drawn ignoring the drawstyle (but don't pay the
# recaching if drawstyle is already "default").
if self.get_drawstyle() != "default":
with cbook._setattr_cm(
self, _drawstyle="default", _transformed_path=None):
self.recache()
self._transform_path(subslice)
tpath, affine = (self._get_transformed_path()
.get_transformed_path_and_affine())
else:
tpath, affine = (self._get_transformed_path()
.get_transformed_path_and_affine())

if len(tpath.vertices):
# subsample the markers if markevery is not None
markevery = self.get_markevery()
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Tests specific to the lines module.
"""

from io import BytesIO
import itertools
import matplotlib.lines as mlines
import pytest
Expand Down Expand Up @@ -195,3 +197,15 @@ def test_nan_is_sorted():
assert line._is_sorted(np.array([1, 2, 3]))
assert line._is_sorted(np.array([1, np.nan, 3]))
assert not line._is_sorted([3, 5] + [np.nan] * 100 + [0, 2])


def test_step_markers():
fig, ax = plt.subplots()
ax.step([0, 1], "-o")
buf1 = BytesIO()
fig.savefig(buf1)
fig, ax = plt.subplots()
ax.plot([0, 0, 1], [0, 1, 1], "-o", markevery=[0, 2])
buf2 = BytesIO()
fig.savefig(buf2)
assert buf1.getvalue() == buf2.getvalue()