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

POC: make scaling optional in Collection.get_linestyle#29304

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rcomer wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromrcomer:collection-get_linestyle
Draft
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -145,15 +145,14 @@ def create_artists(self, legend, orig_handle,
exceptIndexError:
color=orig_handle.get_colors()[0]
try:
dashes=orig_handle.get_dashes()[i]
linestyle=orig_handle.get_linestyle(scaled=False)[i]
exceptIndexError:
dashes=orig_handle.get_dashes()[0]
linestyle=orig_handle.get_linestyle(scaled=False)[0]
try:
lw=orig_handle.get_linewidths()[i]
exceptIndexError:
lw=orig_handle.get_linewidths()[0]
ifdashes[1]isnotNone:
legline.set_dashes(dashes[1])
legline.set_linestyle(linestyle)
legline.set_color(color)
legline.set_transform(trans)
legline.set_linewidth(lw)
Expand Down
12 changes: 10 additions & 2 deletionslib/matplotlib/collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -626,6 +626,11 @@ def set_linestyle(self, ls):
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
complete description.
"""
ifisinstance(ls, (str,tuple)):
self._original_linestyle= [ls]
Copy link
MemberAuthor

@rcomerrcomerDec 13, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I got a lot more failures if I did not make sure this is a list. I note thatCollection.get_facecolor always returns a sequence of colours, having appliedto_rgba_array.

else:
self._original_linestyle=ls

try:
dashes= [mlines._get_dash_pattern(ls)]
exceptValueError:
Expand DownExpand Up@@ -866,8 +871,11 @@ def set_alpha(self, alpha):
defget_linewidth(self):
returnself._linewidths

defget_linestyle(self):
returnself._linestyles
defget_linestyle(self,scaled=False):
ifscaled:
returnself._linestyles

returnself._original_linestyle

def_set_mappable_flags(self):
"""
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/collections.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ class Collection(colorizer.ColorizingArtist):
defset_edgecolor(self,c:ColorType|Sequence[ColorType])->None: ...
defset_alpha(self,alpha:float|Sequence[float]|None)->None: ...
defget_linewidth(self)->float|Sequence[float]: ...
defget_linestyle(self)->LineStyleType|Sequence[LineStyleType]: ...
defget_linestyle(self,scaled:bool= ...)->LineStyleType|Sequence[LineStyleType]: ...
defupdate_scalarmappable(self)->None: ...
defget_fill(self)->bool: ...
defupdate_from(self,other:Artist)->None: ...
Expand Down
5 changes: 3 additions & 2 deletionslib/matplotlib/legend_handler.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -407,7 +407,7 @@ def get_numpoints(self, legend):

def_default_update_prop(self,legend_handle,orig_handle):
lw=orig_handle.get_linewidths()[0]
dashes=orig_handle._us_linestyles[0]
dashes=orig_handle.get_linestyles(scaled=False)[0]
color=orig_handle.get_colors()[0]
legend_handle.set_color(color)
legend_handle.set_linestyle(dashes)
Expand DownExpand Up@@ -798,7 +798,8 @@ def get_first(prop_array):
legend_handle._hatch_color=orig_handle._hatch_color
# Setters are fine for the remaining attributes.
legend_handle.set_linewidth(get_first(orig_handle.get_linewidths()))
legend_handle.set_linestyle(get_first(orig_handle.get_linestyles()))
legend_handle.set_linestyle(
get_first(orig_handle.get_linestyles(scaled=False)))
legend_handle.set_transform(get_first(orig_handle.get_transforms()))
legend_handle.set_figure(orig_handle.get_figure())
# Alpha is already taken into account by the color attributes.
Expand Down
8 changes: 4 additions & 4 deletionslib/matplotlib/tests/test_collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,7 +86,7 @@ def test__EventCollection__get_props():
# check that the default lineoffset matches the input lineoffset
assertprops['lineoffset']==coll.get_lineoffset()
# check that the default linestyle matches the input linestyle
assertcoll.get_linestyle()== [(0,None)]
assertcoll.get_linestyle(scaled=True)== [(0,None)]
# check that the default color matches the input color
forcolorin [coll.get_color(),*coll.get_colors()]:
np.testing.assert_array_equal(color,props['color'])
Expand DownExpand Up@@ -248,7 +248,7 @@ def test__EventCollection__set_lineoffset():
])
deftest__EventCollection__set_prop():
forprop,value,expectedin [
('linestyle','dashed', [(0, (6.0,6.0))]),
('linestyle','dashed', ['dashed']),
('linestyle', (0, (6.,6.)), [(0, (6.0,6.0))]),
('linewidth',5,5),
]:
Expand DownExpand Up@@ -666,11 +666,11 @@ def test_lslw_bcast():
col.set_linestyles(['-','-'])
col.set_linewidths([1,2,3])

assertcol.get_linestyles()== [(0,None)]*6
assertcol.get_linestyles(scaled=True)== [(0,None)]*6
assertcol.get_linewidths()== [1,2,3]*2

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


Expand Down
12 changes: 11 additions & 1 deletionlib/matplotlib/tests/test_legend.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -528,6 +528,16 @@ def test_legend_stackplot():
ax.legend(loc='best')


@mpl.style.context('default')
def test_polycollection_linestyles_unscaled():
fig, ax = plt.subplots()
q = ax.quiver(0, 0, 7, 1, label='v1 + v2', linewidth=3, linestyle='dotted')
leg = ax.legend()
handle, = leg.legend_handles

assert q.get_linestyle(scaled=False)[0] == handle.get_linestyle()


def test_cross_figure_patch_legend():
fig, ax = plt.subplots()
fig2, ax2 = plt.subplots()
Expand DownExpand Up@@ -612,7 +622,7 @@ def test_linecollection_scaled_dashes():
h1, h2, h3 = leg.legend_handles

for oh, lh in zip((lc1, lc2, lc3), (h1, h2, h3)):
assert oh.get_linestyles()[0] == lh._dash_pattern
assert oh.get_linestyles()[0] == lh.get_linestyle()


def test_handler_numpoints():
Expand Down
2 changes: 1 addition & 1 deletionlib/mpl_toolkits/mplot3d/tests/test_legend3d.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,7 +55,7 @@ def test_linecollection_scaled_dashes():
h1,h2,h3=leg.legend_handles

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


deftest_handlerline3d():
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp