MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / draw

Method draw

galleries/examples/event_handling/pong_sgskip.py:194–245  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

192 self.canvas.mpl_connect('key_press_event', self.on_key_press)
193
194 def draw(self):
195 draw_artist = self.ax.draw_artist
196 if self.background is None:
197 self.background = self.canvas.copy_from_bbox(self.ax.bbox)
198
199 # restore the clean slate background
200 self.canvas.restore_region(self.background)
201
202 # show the distractors
203 if self.distract:
204 self.line.set_ydata(np.sin(self.x + self.cnt/self.res))
205 self.line2.set_ydata(np.cos(self.x - self.cnt/self.res))
206 self.line3.set_ydata(np.tan(self.x + self.cnt/self.res))
207 self.line4.set_ydata(np.tan(self.x - self.cnt/self.res))
208 draw_artist(self.line)
209 draw_artist(self.line2)
210 draw_artist(self.line3)
211 draw_artist(self.line4)
212
213 # pucks and pads
214 if self.on:
215 self.ax.draw_artist(self.centerline)
216 for pad in self.pads:
217 pad.disp.set_y(pad.y)
218 pad.disp.set_x(pad.x)
219 self.ax.draw_artist(pad.disp)
220
221 for puck in self.pucks:
222 if puck.update(self.pads):
223 # we only get here if someone scored
224 self.pads[0].disp.set_label(f" {self.pads[0].score}")
225 self.pads[1].disp.set_label(f" {self.pads[1].score}")
226 self.ax.legend(loc='center', framealpha=.2,
227 facecolor='0.5',
228 prop=FontProperties(size='xx-large',
229 weight='bold'))
230
231 self.background = None
232 self.ax.figure.canvas.draw_idle()
233 return
234 puck.disp.set_offsets([[puck.x, puck.y]])
235 self.ax.draw_artist(puck.disp)
236
237 # just redraw the Axes rectangle
238 self.canvas.blit(self.ax.bbox)
239 self.canvas.flush_events()
240 if self.cnt == 50000:
241 # just so we don't get carried away
242 print("...and you've been playing for too long!!!")
243 plt.close()
244
245 self.cnt += 1
246
247 def on_key_press(self, event):
248 if event.key == '3':

Callers 15

on_key_pressMethod · 0.45
tellmeFunction · 0.45
update_titleFunction · 0.45
on_moveMethod · 0.45
on_mouse_moveFunction · 0.45
updateMethod · 0.45
on_pressFunction · 0.45
on_enter_axesFunction · 0.45
on_leave_axesFunction · 0.45
on_enter_figureFunction · 0.45
on_leave_figureFunction · 0.45
on_pressFunction · 0.45

Calls 15

FontPropertiesClass · 0.90
set_ydataMethod · 0.80
copy_from_bboxMethod · 0.45
restore_regionMethod · 0.45
draw_artistMethod · 0.45
set_yMethod · 0.45
set_xMethod · 0.45
updateMethod · 0.45
set_labelMethod · 0.45
legendMethod · 0.45
draw_idleMethod · 0.45
set_offsetsMethod · 0.45

Tested by

no test coverage detected