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

Commitd8f3119

Browse files
committed
POC: make scaling optional in Collection.get_linestyle
1 parenta23ef5a commitd8f3119

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

‎lib/matplotlib/collections.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ def set_linestyle(self, ls):
626626
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
627627
complete description.
628628
"""
629+
ifisinstance(ls, (str,tuple)):
630+
self._original_linestyle= [ls]
631+
else:
632+
self._original_linestyle=ls
633+
629634
try:
630635
dashes= [mlines._get_dash_pattern(ls)]
631636
exceptValueError:
@@ -866,8 +871,11 @@ def set_alpha(self, alpha):
866871
defget_linewidth(self):
867872
returnself._linewidths
868873

869-
defget_linestyle(self):
870-
returnself._linestyles
874+
defget_linestyle(self,scaled=False):
875+
ifscaled:
876+
returnself._linestyles
877+
878+
returnself._original_linestyle
871879

872880
def_set_mappable_flags(self):
873881
"""

‎lib/matplotlib/legend_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def get_numpoints(self, legend):
407407

408408
def_default_update_prop(self,legend_handle,orig_handle):
409409
lw=orig_handle.get_linewidths()[0]
410-
dashes=orig_handle._us_linestyles[0]
410+
dashes=orig_handle.get_linestyles()[0]
411411
color=orig_handle.get_colors()[0]
412412
legend_handle.set_color(color)
413413
legend_handle.set_linestyle(dashes)
@@ -798,7 +798,8 @@ def get_first(prop_array):
798798
legend_handle._hatch_color=orig_handle._hatch_color
799799
# Setters are fine for the remaining attributes.
800800
legend_handle.set_linewidth(get_first(orig_handle.get_linewidths()))
801-
legend_handle.set_linestyle(get_first(orig_handle.get_linestyles()))
801+
legend_handle.set_linestyle(
802+
get_first(orig_handle.get_linestyles(scaled=False)))
802803
legend_handle.set_transform(get_first(orig_handle.get_transforms()))
803804
legend_handle.set_figure(orig_handle.get_figure())
804805
# Alpha is already taken into account by the color attributes.

‎lib/matplotlib/tests/test_collections.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test__EventCollection__get_props():
8686
# check that the default lineoffset matches the input lineoffset
8787
assertprops['lineoffset']==coll.get_lineoffset()
8888
# check that the default linestyle matches the input linestyle
89-
assertcoll.get_linestyle()== [(0,None)]
89+
assertcoll.get_linestyle(scaled=True)== [(0,None)]
9090
# check that the default color matches the input color
9191
forcolorin [coll.get_color(),*coll.get_colors()]:
9292
np.testing.assert_array_equal(color,props['color'])
@@ -248,7 +248,7 @@ def test__EventCollection__set_lineoffset():
248248
])
249249
deftest__EventCollection__set_prop():
250250
forprop,value,expectedin [
251-
('linestyle','dashed', [(0, (6.0,6.0))]),
251+
('linestyle','dashed', ['dashed']),
252252
('linestyle', (0, (6.,6.)), [(0, (6.0,6.0))]),
253253
('linewidth',5,5),
254254
]:
@@ -666,11 +666,11 @@ def test_lslw_bcast():
666666
col.set_linestyles(['-','-'])
667667
col.set_linewidths([1,2,3])
668668

669-
assertcol.get_linestyles()== [(0,None)]*6
669+
assertcol.get_linestyles(scaled=True)== [(0,None)]*6
670670
assertcol.get_linewidths()== [1,2,3]*2
671671

672672
col.set_linestyles(['-','-','-'])
673-
assertcol.get_linestyles()== [(0,None)]*3
673+
assertcol.get_linestyles(scaled=True)== [(0,None)]*3
674674
assert (col.get_linewidths()== [1,2,3]).all()
675675

676676

‎lib/matplotlib/tests/test_legend.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,16 @@ def test_legend_stackplot():
528528
ax.legend(loc='best')
529529

530530

531+
@mpl.style.context('default')
532+
deftest_polycollection_linestyles_unscaled():
533+
fig,ax=plt.subplots()
534+
q=ax.quiver(0,0,7,1,label='v1 + v2',linewidth=3,linestyle='dotted')
535+
leg=ax.legend()
536+
handle,=leg.legend_handles
537+
538+
assertq.get_linestyle(scaled=False)[0]==handle.get_linestyle()
539+
540+
531541
deftest_cross_figure_patch_legend():
532542
fig,ax=plt.subplots()
533543
fig2,ax2=plt.subplots()
@@ -612,7 +622,7 @@ def test_linecollection_scaled_dashes():
612622
h1,h2,h3=leg.legend_handles
613623

614624
foroh,lhinzip((lc1,lc2,lc3), (h1,h2,h3)):
615-
assertoh.get_linestyles()[0]==lh._dash_pattern
625+
assertoh.get_linestyles()[0]==lh.get_linestyle()
616626

617627

618628
deftest_handler_numpoints():

‎lib/mpl_toolkits/mplot3d/tests/test_legend3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_linecollection_scaled_dashes():
5555
h1,h2,h3=leg.legend_handles
5656

5757
foroh,lhinzip((lc1,lc2,lc3), (h1,h2,h3)):
58-
assertoh.get_linestyles()[0]==lh._dash_pattern
58+
assertoh.get_linestyles()[0]==lh.get_linestyle()
5959

6060

6161
deftest_handlerline3d():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp