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

Commit4d648d6

Browse files
authored
Merge pull request#20693 from ericpre/add_set_props_handle_props_selector
Fix setting artists properties of selectors
2 parents7f7bdc9 +893e7cf commit4d648d6

File tree

4 files changed

+280
-121
lines changed

4 files changed

+280
-121
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PolygonSelector
2+
^^^^^^^^^^^^^^^
3+
The *line* attribute is deprecated. If you want to change the selector
4+
artist properties, use the ``set_props`` or ``set_handle_props`` methods.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Setting artist properties of selectors
2+
--------------------------------------
3+
4+
The artist properties of selectors can be changed using the ``set_props`` and
5+
``set_handle_props`` methods.

‎lib/matplotlib/tests/test_widgets.py

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ def onselect(epress, erelease):
9090
asserttool.center== (180,190)
9191

9292

93+
deftest_rectangle_selector_set_props_handle_props():
94+
ax=get_ax()
95+
96+
defonselect(epress,erelease):
97+
pass
98+
99+
tool=widgets.RectangleSelector(ax,onselect,interactive=True,
100+
props=dict(facecolor='b',alpha=0.2),
101+
handle_props=dict(alpha=0.5))
102+
# Create rectangle
103+
do_event(tool,'press',xdata=0,ydata=10,button=1)
104+
do_event(tool,'onmove',xdata=100,ydata=120,button=1)
105+
do_event(tool,'release',xdata=100,ydata=120,button=1)
106+
107+
artist=tool._selection_artist
108+
assertartist.get_facecolor()==mcolors.to_rgba('b',alpha=0.2)
109+
tool.set_props(facecolor='r',alpha=0.3)
110+
assertartist.get_facecolor()==mcolors.to_rgba('r',alpha=0.3)
111+
112+
forartistintool._handles_artists:
113+
assertartist.get_markeredgecolor()=='black'
114+
assertartist.get_alpha()==0.5
115+
tool.set_handle_props(markeredgecolor='r',alpha=0.3)
116+
forartistintool._handles_artists:
117+
assertartist.get_markeredgecolor()=='r'
118+
assertartist.get_alpha()==0.3
119+
120+
93121
deftest_ellipse():
94122
"""For ellipse, test out the key modifiers"""
95123
ax=get_ax()
@@ -185,9 +213,9 @@ def onselect(epress, erelease):
185213

186214
# Check that marker_props worked.
187215
assertmcolors.same_color(
188-
tool._corner_handles.artist.get_markerfacecolor(),'r')
216+
tool._corner_handles.artists[0].get_markerfacecolor(),'r')
189217
assertmcolors.same_color(
190-
tool._corner_handles.artist.get_markeredgecolor(),'b')
218+
tool._corner_handles.artists[0].get_markeredgecolor(),'b')
191219

192220

193221
@pytest.mark.parametrize('interactive', [True,False])
@@ -404,6 +432,34 @@ def onselect(*args):
404432
tool.direction='invalid_string'
405433

406434

435+
deftest_span_selector_set_props_handle_props():
436+
ax=get_ax()
437+
438+
defonselect(epress,erelease):
439+
pass
440+
441+
tool=widgets.SpanSelector(ax,onselect,'horizontal',interactive=True,
442+
props=dict(facecolor='b',alpha=0.2),
443+
handle_props=dict(alpha=0.5))
444+
# Create rectangle
445+
do_event(tool,'press',xdata=0,ydata=10,button=1)
446+
do_event(tool,'onmove',xdata=100,ydata=120,button=1)
447+
do_event(tool,'release',xdata=100,ydata=120,button=1)
448+
449+
artist=tool._selection_artist
450+
assertartist.get_facecolor()==mcolors.to_rgba('b',alpha=0.2)
451+
tool.set_props(facecolor='r',alpha=0.3)
452+
assertartist.get_facecolor()==mcolors.to_rgba('r',alpha=0.3)
453+
454+
forartistintool._handles_artists:
455+
assertartist.get_color()=='b'
456+
assertartist.get_alpha()==0.5
457+
tool.set_handle_props(color='r',alpha=0.3)
458+
forartistintool._handles_artists:
459+
assertartist.get_color()=='r'
460+
assertartist.get_alpha()==0.3
461+
462+
407463
deftest_tool_line_handle():
408464
ax=get_ax()
409465

@@ -781,6 +837,43 @@ def test_polygon_selector():
781837
check_polygon_selector(event_sequence,expected_result,1)
782838

783839

840+
deftest_polygon_selector_set_props_handle_props():
841+
ax=get_ax()
842+
843+
ax._selections_count=0
844+
845+
defonselect(vertices):
846+
ax._selections_count+=1
847+
ax._current_result=vertices
848+
849+
tool=widgets.PolygonSelector(ax,onselect,
850+
props=dict(color='b',alpha=0.2),
851+
handle_props=dict(alpha=0.5))
852+
853+
event_sequence= (polygon_place_vertex(50,50)
854+
+polygon_place_vertex(150,50)
855+
+polygon_place_vertex(50,150)
856+
+polygon_place_vertex(50,50))
857+
858+
for (etype,event_args)inevent_sequence:
859+
do_event(tool,etype,**event_args)
860+
861+
artist=tool._selection_artist
862+
assertartist.get_color()=='b'
863+
assertartist.get_alpha()==0.2
864+
tool.set_props(color='r',alpha=0.3)
865+
assertartist.get_color()=='r'
866+
assertartist.get_alpha()==0.3
867+
868+
forartistintool._handles_artists:
869+
assertartist.get_color()=='b'
870+
assertartist.get_alpha()==0.5
871+
tool.set_handle_props(color='r',alpha=0.3)
872+
forartistintool._handles_artists:
873+
assertartist.get_color()=='r'
874+
assertartist.get_alpha()==0.3
875+
876+
784877
@pytest.mark.parametrize(
785878
"horizOn, vertOn",
786879
[(True,True), (True,False), (False,True)],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp