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

Commit3f7b0f4

Browse files
committed
changing to a function implementation
1 parenta9b012a commit3f7b0f4

File tree

1 file changed

+124
-126
lines changed

1 file changed

+124
-126
lines changed

‎lib/matplotlib/tests/test_backend_bases.py

Lines changed: 124 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -94,138 +94,136 @@ def test_location_event_position():
9494
assertisinstance(event.y,int)
9595

9696

97-
classButtonTest():
98-
def__init__(self,fig_test,fig_ref,button_call,plots=None,
97+
defButtonTest(fig_test,fig_ref,button_call,plots=None,
9998
layout='none'):
10099

101-
"""
102-
Class for testing the home, back and forwards buttons togheter with
103-
layout managers for several types of "subplots".
100+
"""
101+
Function for testing the home, back and forwards buttons togheter with
102+
layout managers for several types of "subplots".
104103
105-
Parameters
106-
----------
107-
fig_test, fig_ref: `.figure.figures`
108-
The figure to compare
104+
Parameters
105+
----------
106+
fig_test, fig_ref: `.figure.figures`
107+
The figure to compare
109108
110-
button_call: {'home', 'back'}
111-
Which buttons to test
109+
button_call: {'home', 'back'}
110+
Which buttons to test
112111
113-
plots: {'subplots', 'subplots_gridspec', 'add_subplopt', 'add_axes'\
112+
plots: {'subplots', 'subplots_gridspec', 'add_subplopt', 'add_axes'\
114113
'axesgrid'}
115-
Which plot configuration to test.
116-
117-
pause : float
118-
The pause time between events.
119-
"""
120-
self.rows_cols=1,2
121-
self.figs=fig_test,fig_ref
122-
self.trans=None,None
123-
self.layout=layout
124-
self.zoom0= (0.5,0.5), (0.5,0.5)
125-
self.zoom1= (0.5,0.5), (0.6,0.54)
126-
self.zoom2= (0.52,0.52), (0.58,0.53)
127-
128-
self.set_layout(True)
129-
self.add_subplots(plots)
130-
self.add_suptitle('Test button: {}, axes: {}, layout manager: {}'.
131-
format(button_call,plots,layout))
132-
133-
ifbutton_call=='home':
134-
self.home_button()
135-
elifbutton_call=='back':
136-
self.back_button()
137-
138-
# set layout managers to False so that the figures don't change
139-
# during saving.
140-
self.set_layout(False)
141-
142-
defadd_suptitle(self,title):
143-
forfiginself.figs:
144-
fig.suptitle(title)
145-
146-
defset_layout(self,bool_):
147-
forfiginself.figs:
148-
ifself.layout=='constrained':
149-
fig.set_constrained_layout(bool_)
150-
elifself.layout=='tight':
151-
arg=dict(rect=(0,0,1,0.95))ifbool_elsebool_
152-
fig.set_tight_layout(arg)
153-
154-
defadd_subplots(self,plots):
155-
rows,cols=self.rows_cols
156-
self.trans= []
157-
forfiginself.figs:
158-
ifplots=='subplots':
159-
ax=fig.subplots(rows,cols,squeeze=False)[rows-1,cols-1]
160-
elifplots=='subplots_gridspec':
161-
ax=fig.subplots(rows,cols,squeeze=False,
162-
gridspec_kw={'left':0.01})[rows-1,cols-1]
163-
elifplots=='add_subplot':
164-
foriinrange(1,rows*cols+1):
165-
ax=fig.add_subplot(rows,cols,i)
166-
elifplots=='add_axes':
167-
width= (1-0.1)/cols-0.1
168-
height= (1-0.1)/rows-0.1
169-
foriinrange(rows):
170-
forjinrange(cols):
171-
x0=j*(width+0.1)+0.1
172-
y0=i*(height+0.1)+0.1
173-
ax=fig.add_axes((x0,y0,width,height))
174-
elifplots=='axesgrid':
175-
ax=AxesGrid(fig,111,nrows_ncols=(2,2),
176-
axes_pad=0.1)[-1]
177-
178-
self.trans.append(ax.transData.transform)
179-
self.draw()
180-
181-
defdraw(self):
182-
forfiginself.figs:
183-
fig.canvas.flush_events()
184-
185-
defhome_button(self):
186-
"""Zoom twice and get back to home with the home button."""
187-
188-
fig_test,fig_ref=self.figs
189-
trans_test,trans_ref=self.trans
190-
#No zoom happens but this is sometimes necessary to get equal results
191-
self.zoom_event(fig_ref,trans_ref,self.zoom0)
192-
self.zoom_event(fig_test,trans_test,self.zoom1)
193-
self.zoom_event(fig_test,trans_test,self.zoom2)
194-
195-
self.move(fig_test,'home')
196-
197-
defback_button(self):
198-
"""
199-
Zoom once in the ref figure, zoom twice in the test figure and use
200-
the back button twice followed by the forward button
201-
"""
202-
fig_test,fig_ref=self.figs
203-
trans_test,trans_ref=self.trans
204-
205-
self.zoom_event(fig_ref,trans_ref,self.zoom1)
206-
self.zoom_event(fig_test,trans_test,self.zoom1)
207-
self.zoom_event(fig_test,trans_test,self.zoom2)
208-
209-
self.move(fig_test,'back')
210-
self.move(fig_test,'back')
211-
self.move(fig_test,'forward')
212-
213-
defzoom_event(self,fig,trans,zoom):
214-
"""Simulate a zoom event from zoom[0] to zoom[1]"""
215-
xy1,xy2=trans(zoom[0]),trans(zoom[1])
216-
press_zoom=MouseEvent('',fig.canvas,xy1[0],xy1[1],button=1)
217-
drag=MouseEvent('',fig.canvas,xy2[0],xy2[1],button=1)
218-
release_zoom=MouseEvent('',fig.canvas,xy2[0],xy2[1],button=1)
219-
220-
fig.canvas.toolbar.press_zoom(press_zoom)
221-
fig.canvas.toolbar.drag_zoom(drag)
222-
fig.canvas.toolbar.release_zoom(release_zoom)
223-
self.draw()
224-
225-
defmove(self,fig,direction):
226-
"""Simulate the back or forward button on fig"""
227-
getattr(fig.canvas.toolbar,direction)()
228-
self.draw()
114+
Which plot configuration to test.
115+
116+
pause : float
117+
The pause time between events.
118+
"""
119+
rows_cols=1,2
120+
figs=fig_test,fig_ref
121+
zoom=[None]*3
122+
zoom[0]= (0.5,0.5), (0.5,0.5)
123+
zoom[1]= (0.5,0.5), (0.6,0.54)
124+
zoom[2]= (0.52,0.52), (0.58,0.53)
125+
126+
set_layout(figs,layout,True)
127+
trans=add_subplots(figs,plots,rows_cols)
128+
add_suptitle(figs,'Test button: {}, axes: {}, layout manager: {}'.
129+
format(button_call,plots,layout))
130+
131+
ifbutton_call=='home':
132+
home_button(figs,trans,zoom)
133+
elifbutton_call=='back':
134+
back_button(figs,trans,zoom)
135+
136+
# set layout managers to False so that the figures don't change
137+
# during saving.
138+
set_layout(figs,layout,False)
139+
140+
defadd_suptitle(figs,title):
141+
forfiginfigs:
142+
fig.suptitle(title)
143+
144+
defset_layout(figs,layout,bool_):
145+
forfiginfigs:
146+
iflayout=='constrained':
147+
fig.set_constrained_layout(bool_)
148+
eliflayout=='tight':
149+
arg=dict(rect=(0,0,1,0.95))ifbool_elsebool_
150+
fig.set_tight_layout(arg)
151+
152+
defadd_subplots(figs,plots,rows_cols):
153+
rows,cols=rows_cols
154+
trans= []
155+
forfiginfigs:
156+
ifplots=='subplots':
157+
ax=fig.subplots(rows,cols,squeeze=False)[rows-1,cols-1]
158+
elifplots=='subplots_gridspec':
159+
ax=fig.subplots(rows,cols,squeeze=False,
160+
gridspec_kw={'left':0.01})[rows-1,cols-1]
161+
elifplots=='add_subplot':
162+
foriinrange(1,rows*cols+1):
163+
ax=fig.add_subplot(rows,cols,i)
164+
elifplots=='add_axes':
165+
width= (1-0.1)/cols-0.1
166+
height= (1-0.1)/rows-0.1
167+
foriinrange(rows):
168+
forjinrange(cols):
169+
x0=j*(width+0.1)+0.1
170+
y0=i*(height+0.1)+0.1
171+
ax=fig.add_axes((x0,y0,width,height))
172+
elifplots=='axesgrid':
173+
ax=AxesGrid(fig,111,nrows_ncols=(2,2),
174+
axes_pad=0.1)[-1]
175+
176+
trans.append(ax.transData.transform)
177+
draw(fig)
178+
returntrans
179+
180+
defdraw(fig):
181+
fig.canvas.flush_events()
182+
183+
defhome_button(figs,trans,zoom):
184+
"""Zoom twice and get back to home with the home button."""
185+
186+
fig_test,fig_ref=figs
187+
trans_test,trans_ref=trans
188+
#No zoom happens but this is sometimes necessary to get equal results
189+
zoom_event(fig_ref,trans_ref,zoom[0])
190+
zoom_event(fig_test,trans_test,zoom[1])
191+
zoom_event(fig_test,trans_test,zoom[2])
192+
193+
move(fig_test,'home')
194+
195+
defback_button(figs,trans,zoom):
196+
"""
197+
Zoom once in the ref figure, zoom twice in the test figure and use
198+
the back button twice followed by the forward button
199+
"""
200+
fig_test,fig_ref=figs
201+
trans_test,trans_ref=trans
202+
203+
zoom_event(fig_ref,trans_ref,zoom[1])
204+
zoom_event(fig_test,trans_test,zoom[1])
205+
zoom_event(fig_test,trans_test,zoom[2])
206+
207+
move(fig_test,'back')
208+
move(fig_test,'back')
209+
move(fig_test,'forward')
210+
211+
defzoom_event(fig,trans,zoom):
212+
"""Simulate a zoom event from zoom[0] to zoom[1]"""
213+
xy1,xy2=trans(zoom[0]),trans(zoom[1])
214+
press_zoom=MouseEvent('',fig.canvas,xy1[0],xy1[1],button=1)
215+
drag=MouseEvent('',fig.canvas,xy2[0],xy2[1],button=1)
216+
release_zoom=MouseEvent('',fig.canvas,xy2[0],xy2[1],button=1)
217+
218+
fig.canvas.toolbar.press_zoom(press_zoom)
219+
fig.canvas.toolbar.drag_zoom(drag)
220+
fig.canvas.toolbar.release_zoom(release_zoom)
221+
draw(fig)
222+
223+
defmove(fig,direction):
224+
"""Simulate the back or forward button on fig"""
225+
getattr(fig.canvas.toolbar,direction)()
226+
draw(fig)
229227

230228

231229
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp