Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jul 27, 2018
1 parent 59d701f commit 72dc4e0
Show file tree
Hide file tree
Showing 3 changed files with 4,339 additions and 0 deletions.
1,150 changes: 1,150 additions & 0 deletions experimental/DataShaderExample.ipynb

Large diffs are not rendered by default.

203 changes: 203 additions & 0 deletions experimental/ipympl.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The Matplotlib Jupyter Widget Backend\n",
"\n",
"Enabling interaction with matplotlib charts in the Jupyter notebook and JupyterLab\n",
"\n",
"https://github.com/matplotlib/jupyter-matplotlib"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Enabling the `widget` backend.\n",
"# This requires jupyter-matplotlib a.k.a. ipympl.\n",
"# ipympl can be install via pip or conda.\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7da8f712c59e40a78067301f5a5c75c2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureCanvasNbAgg()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Testing matplotlib interactions with a simple plot\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.figure(1)\n",
"plt.plot(np.sin(np.linspace(0, 20, 100)))\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0a7c53ea26d9404e81f721cd7fa2af54",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureCanvasNbAgg()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# A more complex example from the matplotlib gallery\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"np.random.seed(0)\n",
"\n",
"n_bins = 10\n",
"x = np.random.randn(1000, 3)\n",
"\n",
"fig, axes = plt.subplots(nrows=2, ncols=2)\n",
"ax0, ax1, ax2, ax3 = axes.flatten()\n",
"\n",
"colors = ['red', 'tan', 'lime']\n",
"ax0.hist(x, n_bins, density=1, histtype='bar', color=colors, label=colors)\n",
"ax0.legend(prop={'size': 10})\n",
"ax0.set_title('bars with legend')\n",
"\n",
"ax1.hist(x, n_bins, density=1, histtype='bar', stacked=True)\n",
"ax1.set_title('stacked bar')\n",
"\n",
"ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)\n",
"ax2.set_title('stack step (unfilled)')\n",
"\n",
"# Make a multiple-histogram of data-sets with different length.\n",
"x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]\n",
"ax3.hist(x_multi, n_bins, histtype='bar')\n",
"ax3.set_title('different sample sizes')\n",
"\n",
"\n",
"fig.tight_layout()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09b306227930436c927d73f4abe4fc25",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(FloatSlider(value=1.0, max=2.0, min=0.02, orientation='vertical'), FigureCanvasNbAgg()))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# When using the `widget` backend from ipympl,\n",
"# fig.canvas is a proper Jupyter interactive widget, which can be embedded in\n",
"# Layout classes like HBox and Vbox.\n",
"\n",
"# One can bound figure attributes to other widget values.\n",
"\n",
"from ipywidgets import HBox, FloatSlider\n",
"\n",
"plt.ioff()\n",
"plt.clf()\n",
"\n",
"slider = FloatSlider(\n",
" orientation='vertical',\n",
" value=1.0,\n",
" min=0.02,\n",
" max=2.0\n",
")\n",
"\n",
"fig = plt.figure(3)\n",
"\n",
"x = np.linspace(0, 20, 500)\n",
"\n",
"lines = plt.plot(x, np.sin(slider.value * x))\n",
"\n",
"def update_lines(change):\n",
" lines[0].set_data(x, np.sin(change.new * x))\n",
" fig.canvas.draw()\n",
" fig.canvas.flush_events()\n",
"\n",
"slider.observe(update_lines, names='value')\n",
"\n",
"HBox([slider, fig.canvas])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"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.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 72dc4e0

Please sign in to comment.