This file is indexed.

/usr/lib/python3/dist-packages/matplotlib/backends/web_backend/nbagg_uat.ipynb is in python3-matplotlib 2.0.0+dfsg1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "from imp import reload"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## UAT for NbAgg backend.\n",
    "\n",
    "The first line simply reloads matplotlib, uses the nbagg backend and then reloads the backend, just to ensure we have the latest modification to the backend code. Note: The underlying JavaScript will not be updated by this process, so a refresh of the browser after clearing the output and saving is necessary to clear everything fully."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "reload(matplotlib)\n",
    "\n",
    "matplotlib.use('nbagg')\n",
    "\n",
    "import matplotlib.backends.backend_nbagg\n",
    "reload(matplotlib.backends.backend_nbagg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 1 - Simple figure creation using pyplot\n",
    "\n",
    "Should produce a figure window which is interactive with the pan and zoom buttons. (Do not press the close button, but any others may be used)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.backends.backend_webagg_core\n",
    "reload(matplotlib.backends.backend_webagg_core)\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.interactive(False)\n",
    "\n",
    "fig1 = plt.figure()\n",
    "plt.plot(range(10))\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 2 - Creation of another figure, without the need to do plt.figure.\n",
    "\n",
    "As above, a new figure should be created."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.plot([3, 2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 3 - Connection info\n",
    "\n",
    "The printout should show that there are two figures which have active CommSockets, and no figures pending show."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "print(matplotlib.backends.backend_nbagg.connection_info())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 4 - Closing figures\n",
    "\n",
    "Closing a specific figure instance should turn the figure into a plain image - the UI should have been removed. In this case, scroll back to the first figure and assert this is the case."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.close(fig1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 5 - No show without plt.show in non-interactive mode\n",
    "\n",
    "Simply doing a plt.plot should not show a new figure, nor indeed update an existing one (easily verified in UAT 6).\n",
    "The output should simply be a list of Line2D instances."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.plot(range(10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 6 - Connection information\n",
    "\n",
    "We just created a new figure, but didn't show it. Connection info should no longer have \"Figure 1\" (as we closed it in UAT 4) and should have figure 2 and 3, with Figure 3 without any connections. There should be 1 figure pending."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "print(matplotlib.backends.backend_nbagg.connection_info())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 7 - Show of previously created figure\n",
    "\n",
    "We should be able to show a figure we've previously created. The following should produce two figure windows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.show()\n",
    "plt.figure()\n",
    "plt.plot(range(5))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 8 - Interactive mode\n",
    "\n",
    "In interactive mode, creating a line should result in a figure being shown."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.interactive(True)\n",
    "plt.figure()\n",
    "plt.plot([3, 2, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Subsequent lines should be added to the existing figure, rather than creating a new one."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.plot(range(3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calling connection_info in interactive mode should not show any pending figures."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "print(matplotlib.backends.backend_nbagg.connection_info())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Disable interactive mode again."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.interactive(False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 9 - Multiple shows\n",
    "\n",
    "Unlike most of the other matplotlib backends, we may want to see a figure multiple times (with or without synchronisation between the views, though the former is not yet implemented). Assert that plt.gcf().canvas.manager.reshow() results in another figure window which is synchronised upon pan & zoom."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plt.gcf().canvas.manager.reshow()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 10 - Saving notebook\n",
    "\n",
    "Saving the notebook (with CTRL+S or File->Save) should result in the saved notebook having static versions of the figues embedded within. The image should be the last update from user interaction and interactive plotting. (check by converting with ``ipython nbconvert <notebook>``)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 11 - Creation of a new figure on second show\n",
    "\n",
    "Create a figure, show it, then create a new axes and show it. The result should be a new figure.\n",
    "\n",
    "**BUG: Sometimes this doesn't work - not sure why (@pelson).**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "plt.show()\n",
    "\n",
    "plt.plot([1, 2, 3])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 12 - OO interface\n",
    "\n",
    "Should produce a new figure and plot it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from matplotlib.backends.backend_nbagg import new_figure_manager,show\n",
    "\n",
    "manager = new_figure_manager(1000)\n",
    "fig = manager.canvas.figure\n",
    "ax = fig.add_subplot(1,1,1)\n",
    "ax.plot([1,2,3])\n",
    "fig.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## UAT 13 - Animation\n",
    "\n",
    "The following should generate an animated line:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.animation as animation\n",
    "import numpy as np\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "x = np.arange(0, 2*np.pi, 0.01)        # x-array\n",
    "line, = ax.plot(x, np.sin(x))\n",
    "\n",
    "def animate(i):\n",
    "    line.set_ydata(np.sin(x+i/10.0))  # update the data\n",
    "    return line,\n",
    "\n",
    "#Init only required for blitting to give a clean slate.\n",
    "def init():\n",
    "    line.set_ydata(np.ma.array(x, mask=True))\n",
    "    return line,\n",
    "\n",
    "ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,\n",
    "                              interval=32., blit=True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 14 - Keyboard shortcuts in IPython after close of figure\n",
    "\n",
    "After closing the previous figure (with the close button above the figure) the IPython keyboard shortcuts should still function.\n",
    "\n",
    "### UAT 15 - Figure face colours\n",
    "\n",
    "The nbagg honours all colours appart from that of the figure.patch. The two plots below should produce a figure with a transparent background and a red background respectively (check the transparency by closing the figure, and dragging the resulting image over other content). There should be no yellow figure."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib\n",
    "matplotlib.rcParams.update({'figure.facecolor': 'red',\n",
    "                            'savefig.facecolor': 'yellow'})\n",
    "plt.figure()\n",
    "plt.plot([3, 2, 1])\n",
    "\n",
    "with matplotlib.rc_context({'nbagg.transparent': False}):\n",
    "    plt.figure()\n",
    "\n",
    "plt.plot([3, 2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 16 - Events\n",
    "\n",
    "Pressing any keyboard key or mouse button (or scrolling) should cycle the line line while the figure has focus.  The figure should have focus by default when it is created and re-gain it by clicking on the canvas.  Clicking anywhere outside of the figure should release focus, but moving the mouse out of the figure should not release focus."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import itertools\n",
    "fig, ax = plt.subplots()\n",
    "x = np.linspace(0,10,10000)\n",
    "y = np.sin(x)\n",
    "ln, = ax.plot(x,y)\n",
    "evt = []\n",
    "colors = iter(itertools.cycle(['r', 'g', 'b', 'k', 'c']))\n",
    "def on_event(event):\n",
    "    if event.name.startswith('key'):\n",
    "        fig.suptitle('%s: %s' % (event.name, event.key))\n",
    "    elif event.name == 'scroll_event':\n",
    "        fig.suptitle('%s: %s' % (event.name, event.step))\n",
    "    else:\n",
    "        fig.suptitle('%s: %s' % (event.name, event.button))\n",
    "    evt.append(event)\n",
    "    ln.set_color(next(colors))\n",
    "    fig.canvas.draw()\n",
    "    fig.canvas.draw_idle()\n",
    "\n",
    "fig.canvas.mpl_connect('button_press_event', on_event)\n",
    "fig.canvas.mpl_connect('button_release_event', on_event)\n",
    "fig.canvas.mpl_connect('scroll_event', on_event)\n",
    "fig.canvas.mpl_connect('key_press_event', on_event)\n",
    "fig.canvas.mpl_connect('key_release_event', on_event)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT 17 - Timers\n",
    "\n",
    "Single-shot timers follow a completely different code path in the nbagg backend than regular timers (such as those used in the animation example above.)  The next set of tests ensures that both \"regular\" and \"single-shot\" timers work properly.\n",
    "\n",
    "The following should show a simple clock that updates twice a second:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "text = ax.text(0.5, 0.5, '', ha='center')\n",
    "\n",
    "def update(text):\n",
    "    text.set(text=time.ctime())\n",
    "    text.axes.figure.canvas.draw()\n",
    "    \n",
    "timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
    "timer.start()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, the following should only update once and then stop:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "text = ax.text(0.5, 0.5, '', ha='center') \n",
    "timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
    "\n",
    "timer.single_shot = True\n",
    "timer.start()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And the next two examples should never show any visible text at all:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "text = ax.text(0.5, 0.5, '', ha='center')\n",
    "timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
    "\n",
    "timer.start()\n",
    "timer.stop()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "text = ax.text(0.5, 0.5, '', ha='center')\n",
    "timer = fig.canvas.new_timer(500, [(update, [text], {})])\n",
    "\n",
    "timer.single_shot = True\n",
    "timer.start()\n",
    "timer.stop()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### UAT17 - stoping figure when removed from DOM\n",
    "\n",
    "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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "ax.plot(range(5))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Running the cell below will re-show the figure. After this, re-running the cell above should result in a new figure number."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig.canvas.manager.reshow()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}