Skip to content

remove backend matplotlib.use('nbagg') and add ipympl #33

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -24,7 +27,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -43,7 +49,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -57,7 +66,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -71,7 +83,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -93,7 +108,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -112,7 +130,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -131,7 +152,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -143,7 +167,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -155,7 +182,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -170,7 +200,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -182,7 +215,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -201,9 +237,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"print(\"Shape of X:\", x.shape)\n",
Expand All @@ -221,7 +255,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -246,7 +283,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -261,7 +301,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -271,27 +314,34 @@
"z = x * y\n",
"print(z.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 4
}
46 changes: 18 additions & 28 deletions AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"slideshow": {
"slide_type": "-"
}
Expand Down Expand Up @@ -87,33 +90,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are working interactively at an (I)python prompt, the GUI framework is not critical (mostly aesthetic) however when working in Jupyter we need to pick a backend that integrates with Jupyter (javascript) framework.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still useful content for people who will are reading this that will mostly work at a prompt. Can it just be re-worrked rather than fully deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that part back. Hope that's fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this alright, or needs rephrasing?

"\n",
"To select the backend use ``matplotlib.use(\"backend_name\")``, in this case we want ``'nbagg'``\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"matplotlib.use('nbagg')\n",
"print(matplotlib.get_backend())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"which must be done *before* you `import matplotlib.pyplot as plt`.\n",
"\n",
"You can also set the backend via an 'ipython magic' ``%matplotlib backend_name``. In addition to setting the backend, the magic also calls `plt.ion()`, which puts Matplotlib in 'interacitve mode' (the inverse is `plt.ioff()`). In 'interactive mode' figures are shown (injected into the web page in the notebook) as soon as they are created. Otherwise, figures are not shown until you explicitly call `plt.show()`.\n",
"\n",
"\n",
"In these tutorials we will mostly work in non-interactive mode for better control of when\n",
"figures are shown in the notebooks.\n",
"This also better mimics the behavior you can expect in regular python scripts.\n"
"This also better mimics the behavior you can expect in regular python scripts."
]
},
{
Expand Down Expand Up @@ -436,7 +415,18 @@
"metadata": {},
"outputs": [],
"source": [
"%load exercises/1.1-subplots_and_basic_plotting.py"
"# %load exercises/1.1-subplots_and_basic_plotting.py\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Try to reproduce the figure shown in images/exercise_1-1.png\n",
"\n",
"# Our data...\n",
"x = np.linspace(0, 10, 100)\n",
"y1, y2, y3 = np.cos(x), np.cos(x + 1), np.cos(x + 2)\n",
"names = ['Signal 1', 'Signal 2', 'Signal 3']\n",
"\n",
"# Can you figure out what to do next to plot x vs y1, y2, and y3 on one figure?\n"
]
},
{
Expand Down Expand Up @@ -475,9 +465,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
48 changes: 43 additions & 5 deletions AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"from __future__ import print_function\n",
"import numpy as np\n",
"import matplotlib\n",
"matplotlib.use('nbagg')\n",
"import matplotlib.pyplot as plt"
]
},
Expand Down Expand Up @@ -234,7 +233,31 @@
"metadata": {},
"outputs": [],
"source": [
"%load exercises/2.1-bar_and_fill_between.py"
"# %load exercises/2.1-bar_and_fill_between.py\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"np.random.seed(1)\n",
"\n",
"# Generate data...\n",
"y_raw = np.random.randn(1000).cumsum() + 15\n",
"x_raw = np.linspace(0, 24, y_raw.size)\n",
"\n",
"# Get averages of every 100 samples...\n",
"x_pos = x_raw.reshape(-1, 100).min(axis=1)\n",
"y_avg = y_raw.reshape(-1, 100).mean(axis=1)\n",
"y_err = y_raw.reshape(-1, 100).ptp(axis=1)\n",
"\n",
"bar_width = x_pos[1] - x_pos[0]\n",
"\n",
"# Make a made up future prediction with a fake confidence\n",
"x_pred = np.linspace(0, 30)\n",
"y_max_pred = y_avg[0] + y_err[0] + 2.3 * x_pred\n",
"y_min_pred = y_avg[0] - y_err[0] + 1.2 * x_pred\n",
"\n",
"# Just so you don't have to guess at the colors...\n",
"barcolor, linecolor, fillcolor = 'wheat', 'salmon', 'lightblue'\n",
"\n",
"# Now you're on your own!\n"
]
},
{
Expand Down Expand Up @@ -417,7 +440,22 @@
"metadata": {},
"outputs": [],
"source": [
"%load exercises/2.2-vmin_vmax_imshow_and_colorbars.py"
"# %load exercises/2.2-vmin_vmax_imshow_and_colorbars.py\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"np.random.seed(1)\n",
"\n",
"# Generate random data with different ranges...\n",
"data1 = np.random.random((10, 10))\n",
"data2 = 2 * np.random.random((10, 10))\n",
"data3 = 3 * np.random.random((10, 10))\n",
"\n",
"# Set up our figure and axes...\n",
"fig, axes = plt.subplots(ncols=3, figsize=plt.figaspect(0.5))\n",
"fig.tight_layout() # Make the subplots fill up the figure a bit more...\n",
"cax = fig.add_axes([0.25, 0.1, 0.55, 0.03]) # Add an axes for the colorbar\n",
"\n",
"# Now you're on your own!\n"
]
},
{
Expand Down Expand Up @@ -462,9 +500,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading