|
201 | 201 | "source": [
|
202 | 202 | "# Interactions with other widgets and layouting\n",
|
203 | 203 | "\n",
|
204 |
| - "When you want to embed the figure into a layout of other widgets you should call `plt.ioff()` before creating the figure otherwise code inside of `plt.figure()` will display the canvas automatically and outside of your layout. " |
| 204 | + "When you want to embed the figure into a layout of other widgets you should call `plt.ioff()` before creating the figure otherwise `plt.figure()` will trigger a display of the canvas automatically and outside of your layout. " |
205 | 205 | ]
|
206 | 206 | },
|
207 | 207 | {
|
|
225 | 225 | "# this is default but if this notebook is executed out of order it may have been turned off\n",
|
226 | 226 | "plt.ion()\n",
|
227 | 227 | "\n",
|
228 |
| - "\n", |
229 | 228 | "fig = plt.figure()\n",
|
230 | 229 | "ax = fig.gca()\n",
|
231 | 230 | "ax.imshow(Z)\n",
|
|
268 | 267 | ")"
|
269 | 268 | ]
|
270 | 269 | },
|
271 |
| - { |
272 |
| - "cell_type": "markdown", |
273 |
| - "metadata": {}, |
274 |
| - "source": [ |
275 |
| - "### Fixing the double display with `ipywidgets.Output`\n", |
276 |
| - "\n", |
277 |
| - "Using `plt.ioff` use matplotlib to avoid the double display of the plot. You can also use `ipywidgets.Output` to capture the plot display to prevent this" |
278 |
| - ] |
279 |
| - }, |
280 |
| - { |
281 |
| - "cell_type": "code", |
282 |
| - "execution_count": null, |
283 |
| - "metadata": {}, |
284 |
| - "outputs": [], |
285 |
| - "source": [ |
286 |
| - "out = widgets.Output()\n", |
287 |
| - "with out:\n", |
288 |
| - " fig = plt.figure()\n", |
289 |
| - "\n", |
290 |
| - "ax = fig.gca()\n", |
291 |
| - "ax.imshow(Z)\n", |
292 |
| - "\n", |
293 |
| - "widgets.AppLayout(\n", |
294 |
| - " center=out,\n", |
295 |
| - " footer=widgets.Button(icon='check'),\n", |
296 |
| - " pane_heights=[0, 6, 1]\n", |
297 |
| - ")" |
298 |
| - ] |
299 |
| - }, |
300 | 270 | {
|
301 | 271 | "cell_type": "markdown",
|
302 | 272 | "metadata": {},
|
|
446 | 416 | "display(widgets.VBox([slider, fig.canvas]))\n",
|
447 | 417 | "display(out)"
|
448 | 418 | ]
|
449 |
| - }, |
450 |
| - { |
451 |
| - "cell_type": "code", |
452 |
| - "execution_count": null, |
453 |
| - "metadata": {}, |
454 |
| - "outputs": [], |
455 |
| - "source": [] |
456 | 419 | }
|
457 | 420 | ],
|
458 | 421 | "metadata": {
|
459 | 422 | "kernelspec": {
|
460 |
| - "display_name": "Python 3", |
| 423 | + "display_name": "Python 3 (ipykernel)", |
461 | 424 | "language": "python",
|
462 | 425 | "name": "python3"
|
463 | 426 | },
|
|
471 | 434 | "name": "python",
|
472 | 435 | "nbconvert_exporter": "python",
|
473 | 436 | "pygments_lexer": "ipython3",
|
474 |
| - "version": "3.7.8" |
| 437 | + "version": "3.9.7" |
475 | 438 | },
|
476 | 439 | "widgets": {
|
477 | 440 | "application/vnd.jupyter.widget-state+json": {
|
|
0 commit comments