close

[Solved] Jupyter Notebook: interactive plot with widgets

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Jupyter Notebook: interactive plot with widgets in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Jupyter Notebook: interactive plot with widgets Error Occurs?

Today I get the following error Jupyter Notebook: interactive plot with widgets in python.

How To Solve Jupyter Notebook: interactive plot with widgets Error ?

  1. How To Solve Jupyter Notebook: interactive plot with widgets Error ?

    To Solve Jupyter Notebook: interactive plot with widgets Error This is an issue (?) introduced in the last version of jupyter and/or ipywidgets. One workaround I found was to add the line plt.show() at the end of plot_func.

  2. Jupyter Notebook: interactive plot with widgets

    To Solve Jupyter Notebook: interactive plot with widgets Error This is an issue (?) introduced in the last version of jupyter and/or ipywidgets. One workaround I found was to add the line plt.show() at the end of plot_func.

Solution 1

As you want to change the figure, instead of creating a new one, may I suggest the following way:

  1. Use an interactive backend; %matplotlib notebook
  2. Update the line in the plot, instead of drawing new ones.

So the code could look something like this:

%matplotlib notebook
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
line, = ax.plot(x, np.sin(x))

def update(w = 1.0):
    line.set_ydata(np.sin(w * x))
    fig.canvas.draw_idle()

interact(update);
enter image description here

Alternatively you may use plt.show() as in this answer.

Solution 2

This is an issue (?) introduced in the last version of jupyter and/or ipywidgets. One workaround I found was to add the line plt.show() at the end of plot_func.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read