Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9e6a72c

Browse files
committed
Properly position markers in step plots.
While it may appear costly to recache the path at every draw, this onlyoccurs when using step plots with markers (a relatively rare case) andis still better than before the bug was introduced, where step plotswould need to be recomputed at every draw, regardless of whether markersare present.
1 parentf881e9b commit9e6a72c

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
ifself.get_path_effects():
746746
frommatplotlib.patheffectsimportPathEffectRenderer
747747
renderer=PathEffectRenderer(self.get_path_effects(),renderer)
748748

749749
renderer.open_group('line2d',self.get_gid())
750750
ifself._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
iflen(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+
ifself.get_drawstyle()!="default":
804+
withcbook._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
iflen(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+
fromioimportBytesIO
46
importitertools
57
importmatplotlib.linesasmlines
68
importpytest
@@ -195,3 +197,15 @@ def test_nan_is_sorted():
195197
assertline._is_sorted(np.array([1,2,3]))
196198
assertline._is_sorted(np.array([1,np.nan,3]))
197199
assertnotline._is_sorted([3,5]+ [np.nan]*100+ [0,2])
200+
201+
202+
deftest_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+
assertbuf1.getvalue()==buf2.getvalue()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp