ipympl
#
Since the Jupyter widget ecosystem is developing too quickly, the Matplotlib developers have decided to outsource the support to a separate module: ipympl
or jupyter-matplotlib.
Installation#
ipympl
is installed in both the kernel and the Jupyter environment
pipenv install ipympl
Installing ipympl…
Adding ipympl to Pipfile's [packages]…
✔ Installation Succeeded
…
Then you can activate the Jupyter backend in notebooks by using the following Matplotlib-Magic:
[1]:
%matplotlib widget
Examples#
Simple Matplotlib interaction#
[2]:
import matplotlib.pyplot as plt
import numpy as np
plt.figure(1)
plt.plot(np.sin(np.linspace(0, 20, 100)))
plt.show()
3D plot: subplot3d_demo.py#
[3]:
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Grab some test data.
X, Y, Z = axes3d.get_test_data(0.05)
# Plot a basic wireframe.
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
fig.canvas.layout.max_width = '800px'
plt.show()
More complex example from the Matplotlib gallery#
[4]:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
n_bins = 10
x = np.random.randn(1000, 3)
fig, axes = plt.subplots(nrows=2, ncols=2)
ax0, ax1, ax2, ax3 = axes.flatten()
colors = ['red', 'tan', 'lime']
ax0.hist(x, n_bins, density=1, histtype='bar', color=colors, label=colors)
ax0.legend(prop={'size': 10})
ax0.set_title('bars with legend')
ax1.hist(x, n_bins, density=1, histtype='bar', stacked=True)
ax1.set_title('stacked bar')
ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)
ax2.set_title('stack step (unfilled)')
# Make a multiple-histogram of data-sets with different length.
x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
ax3.hist(x_multi, n_bins, histtype='bar')
ax3.set_title('different sample sizes')
fig.tight_layout()
plt.show()