Inline Interactive Plots with Matplotlib
Ensure that the matplotlib and ipympl are installed on your system with the following command –
On Windows
py -m pip install --upgrade matplotlib ipympl
On Linux
python3 -m pip install --upgrade matplotlib ipympl
ipympl is required to create inline interactive plots in jupyter-notebooks with matplotlib. Include the following line of code at the beginning of the cell whose output is wanted interactive –
%matplotlib widget
Example
Python3
% matplotlib widget # place the regular matplotlib code below import matplotlib.pyplot as plt x = [ 1 , 2 , 3 ] y = [ 5 , 2 , 3 ] plt.plot(x,y) plt.show() |
Output:
The interactive controls can be seen at the top left corner in Figure 2.
How to Use JupyterLab Inline Interactive Plots
This article shows how to create inline interactive plots in JupyterLab with Python-3 programming language. It assumes basic familiarity with JupyterLab/Jupyter Notebooks and Python-3. By the end of the article, the reader will be able to understand and create inline interactive plots with Matplotlib, Bokeh, and Plotly plotting libraries inside a Jupyter-Notebook (in JupyterLab) using Python-3.
Contact Us