Skip to content

Commit c901b8d

Browse files
ianhitacaswell
andcommitted
add blitting to nbagg UAT notebook + correct the numbering of stopping figure
taking the example from #9240 Co-Authored-By: Thomas A Caswell <tcaswell@gmail.com>
1 parent 78c182d commit c901b8d

File tree

1 file changed

+75
-82
lines changed

1 file changed

+75
-82
lines changed

lib/matplotlib/backends/web_backend/nbagg_uat.ipynb

+75-82
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"metadata": {
7-
"collapsed": false
8-
},
6+
"metadata": {},
97
"outputs": [],
108
"source": [
119
"from imp import reload"
@@ -23,9 +21,7 @@
2321
{
2422
"cell_type": "code",
2523
"execution_count": null,
26-
"metadata": {
27-
"collapsed": false
28-
},
24+
"metadata": {},
2925
"outputs": [],
3026
"source": [
3127
"import matplotlib\n",
@@ -49,9 +45,7 @@
4945
{
5046
"cell_type": "code",
5147
"execution_count": null,
52-
"metadata": {
53-
"collapsed": false
54-
},
48+
"metadata": {},
5549
"outputs": [],
5650
"source": [
5751
"import matplotlib.backends.backend_webagg_core\n",
@@ -78,9 +72,7 @@
7872
{
7973
"cell_type": "code",
8074
"execution_count": null,
81-
"metadata": {
82-
"collapsed": false
83-
},
75+
"metadata": {},
8476
"outputs": [],
8577
"source": [
8678
"plt.plot([3, 2, 1])\n",
@@ -99,9 +91,7 @@
9991
{
10092
"cell_type": "code",
10193
"execution_count": null,
102-
"metadata": {
103-
"collapsed": false
104-
},
94+
"metadata": {},
10595
"outputs": [],
10696
"source": [
10797
"print(matplotlib.backends.backend_nbagg.connection_info())"
@@ -119,12 +109,11 @@
119109
{
120110
"cell_type": "code",
121111
"execution_count": null,
122-
"metadata": {
123-
"collapsed": false
124-
},
112+
"metadata": {},
125113
"outputs": [],
126114
"source": [
127-
"plt.close(fig1)"
115+
"plt.close(fig1)\n",
116+
"plt.close('all')"
128117
]
129118
},
130119
{
@@ -140,9 +129,7 @@
140129
{
141130
"cell_type": "code",
142131
"execution_count": null,
143-
"metadata": {
144-
"collapsed": false
145-
},
132+
"metadata": {},
146133
"outputs": [],
147134
"source": [
148135
"plt.plot(range(10))"
@@ -160,9 +147,7 @@
160147
{
161148
"cell_type": "code",
162149
"execution_count": null,
163-
"metadata": {
164-
"collapsed": false
165-
},
150+
"metadata": {},
166151
"outputs": [],
167152
"source": [
168153
"print(matplotlib.backends.backend_nbagg.connection_info())"
@@ -180,9 +165,7 @@
180165
{
181166
"cell_type": "code",
182167
"execution_count": null,
183-
"metadata": {
184-
"collapsed": false
185-
},
168+
"metadata": {},
186169
"outputs": [],
187170
"source": [
188171
"plt.show()\n",
@@ -203,9 +186,7 @@
203186
{
204187
"cell_type": "code",
205188
"execution_count": null,
206-
"metadata": {
207-
"collapsed": false
208-
},
189+
"metadata": {},
209190
"outputs": [],
210191
"source": [
211192
"plt.interactive(True)\n",
@@ -223,9 +204,7 @@
223204
{
224205
"cell_type": "code",
225206
"execution_count": null,
226-
"metadata": {
227-
"collapsed": false
228-
},
207+
"metadata": {},
229208
"outputs": [],
230209
"source": [
231210
"plt.plot(range(3))"
@@ -241,9 +220,7 @@
241220
{
242221
"cell_type": "code",
243222
"execution_count": null,
244-
"metadata": {
245-
"collapsed": false
246-
},
223+
"metadata": {},
247224
"outputs": [],
248225
"source": [
249226
"print(matplotlib.backends.backend_nbagg.connection_info())"
@@ -259,9 +236,7 @@
259236
{
260237
"cell_type": "code",
261238
"execution_count": null,
262-
"metadata": {
263-
"collapsed": false
264-
},
239+
"metadata": {},
265240
"outputs": [],
266241
"source": [
267242
"plt.interactive(False)"
@@ -279,9 +254,7 @@
279254
{
280255
"cell_type": "code",
281256
"execution_count": null,
282-
"metadata": {
283-
"collapsed": false
284-
},
257+
"metadata": {},
285258
"outputs": [],
286259
"source": [
287260
"plt.gcf().canvas.manager.reshow()"
@@ -310,9 +283,7 @@
310283
{
311284
"cell_type": "code",
312285
"execution_count": null,
313-
"metadata": {
314-
"collapsed": false
315-
},
286+
"metadata": {},
316287
"outputs": [],
317288
"source": [
318289
"fig = plt.figure()\n",
@@ -335,9 +306,7 @@
335306
{
336307
"cell_type": "code",
337308
"execution_count": null,
338-
"metadata": {
339-
"collapsed": false
340-
},
309+
"metadata": {},
341310
"outputs": [],
342311
"source": [
343312
"from matplotlib.backends.backend_nbagg import new_figure_manager,show\n",
@@ -361,9 +330,7 @@
361330
{
362331
"cell_type": "code",
363332
"execution_count": null,
364-
"metadata": {
365-
"collapsed": false
366-
},
333+
"metadata": {},
367334
"outputs": [],
368335
"source": [
369336
"import matplotlib.animation as animation\n",
@@ -384,7 +351,7 @@
384351
" return line,\n",
385352
"\n",
386353
"ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,\n",
387-
" interval=32., blit=True)\n",
354+
" interval=100., blit=True)\n",
388355
"plt.show()"
389356
]
390357
},
@@ -404,9 +371,7 @@
404371
{
405372
"cell_type": "code",
406373
"execution_count": null,
407-
"metadata": {
408-
"collapsed": false
409-
},
374+
"metadata": {},
410375
"outputs": [],
411376
"source": [
412377
"import matplotlib\n",
@@ -430,9 +395,7 @@
430395
{
431396
"cell_type": "code",
432397
"execution_count": null,
433-
"metadata": {
434-
"collapsed": false
435-
},
398+
"metadata": {},
436399
"outputs": [],
437400
"source": [
438401
"import itertools\n",
@@ -477,9 +440,7 @@
477440
{
478441
"cell_type": "code",
479442
"execution_count": null,
480-
"metadata": {
481-
"collapsed": false
482-
},
443+
"metadata": {},
483444
"outputs": [],
484445
"source": [
485446
"import time\n",
@@ -506,9 +467,7 @@
506467
{
507468
"cell_type": "code",
508469
"execution_count": null,
509-
"metadata": {
510-
"collapsed": false
511-
},
470+
"metadata": {},
512471
"outputs": [],
513472
"source": [
514473
"fig, ax = plt.subplots()\n",
@@ -531,9 +490,7 @@
531490
{
532491
"cell_type": "code",
533492
"execution_count": null,
534-
"metadata": {
535-
"collapsed": false
536-
},
493+
"metadata": {},
537494
"outputs": [],
538495
"source": [
539496
"fig, ax = plt.subplots()\n",
@@ -549,9 +506,7 @@
549506
{
550507
"cell_type": "code",
551508
"execution_count": null,
552-
"metadata": {
553-
"collapsed": false
554-
},
509+
"metadata": {},
555510
"outputs": [],
556511
"source": [
557512
"fig, ax = plt.subplots()\n",
@@ -569,17 +524,15 @@
569524
"cell_type": "markdown",
570525
"metadata": {},
571526
"source": [
572-
"### UAT17 - stopping figure when removed from DOM\n",
527+
"### UAT 18 - stopping figure when removed from DOM\n",
573528
"\n",
574529
"When the div that contains from the figure is removed from the DOM the figure should shut down it's comm, and if the python-side figure has no more active comms, it should destroy the figure. Repeatedly running the cell below should always have the same figure number"
575530
]
576531
},
577532
{
578533
"cell_type": "code",
579534
"execution_count": null,
580-
"metadata": {
581-
"collapsed": false
582-
},
535+
"metadata": {},
583536
"outputs": [],
584537
"source": [
585538
"fig, ax = plt.subplots()\n",
@@ -597,20 +550,60 @@
597550
{
598551
"cell_type": "code",
599552
"execution_count": null,
600-
"metadata": {
601-
"collapsed": false
602-
},
553+
"metadata": {},
603554
"outputs": [],
604555
"source": [
605556
"fig.canvas.manager.reshow()"
606557
]
607558
},
608559
{
609-
"cell_type": "code",
610-
"execution_count": null,
560+
"cell_type": "markdown",
611561
"metadata": {
612562
"collapsed": true
613563
},
564+
"source": [
565+
"### UAT 19 - Blitting\n",
566+
"\n",
567+
"Clicking on the figure should plot a green horizontal line moving up the axes."
568+
]
569+
},
570+
{
571+
"cell_type": "code",
572+
"execution_count": null,
573+
"metadata": {},
574+
"outputs": [],
575+
"source": [
576+
"import itertools\n",
577+
"\n",
578+
"cnt = itertools.count()\n",
579+
"bg = None\n",
580+
"\n",
581+
"def onclick_handle(event):\n",
582+
" \"\"\"Should draw elevating green line on each mouse click\"\"\"\n",
583+
" global bg\n",
584+
" if bg is None:\n",
585+
" bg = ax.figure.canvas.copy_from_bbox(ax.bbox) \n",
586+
" ax.figure.canvas.restore_region(bg)\n",
587+
"\n",
588+
" cur_y = (next(cnt) % 10) * 0.1\n",
589+
" ln.set_ydata([cur_y, cur_y])\n",
590+
" ax.draw_artist(ln)\n",
591+
" ax.figure.canvas.blit(ax.bbox)\n",
592+
"\n",
593+
"\n",
594+
"fig, ax = plt.subplots()\n",
595+
"ax.plot([0, 1], [0, 1], 'r')\n",
596+
"ln, = ax.plot([0, 1], [0, 0], 'g', animated=True)\n",
597+
"plt.show()\n",
598+
"ax.figure.canvas.draw()\n",
599+
"\n",
600+
"ax.figure.canvas.mpl_connect('button_press_event', onclick_handle)"
601+
]
602+
},
603+
{
604+
"cell_type": "code",
605+
"execution_count": null,
606+
"metadata": {},
614607
"outputs": [],
615608
"source": []
616609
}
@@ -631,9 +624,9 @@
631624
"name": "python",
632625
"nbconvert_exporter": "python",
633626
"pygments_lexer": "ipython3",
634-
"version": "3.4.3"
627+
"version": "3.8.5"
635628
}
636629
},
637630
"nbformat": 4,
638-
"nbformat_minor": 0
631+
"nbformat_minor": 1
639632
}

0 commit comments

Comments
 (0)