Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

remove broken event loop code #266

Closed
wants to merge 1 commit into from
Closed

Conversation

ianhi
Copy link
Collaborator

@ianhi ianhi commented Sep 26, 2020

fixes: #79

A potential future ipympl specific improvement was mentioned in #79 (comment)

fixes: matplotlib#79. A potential ipympl specific improvement was mentioned in matplotlib#79 (comment)
@ianhi
Copy link
Collaborator Author

ianhi commented Sep 26, 2020

@Michael-Equi can you confirm this fixes your issue. You can install with pip install git+https://github.com/ianhi/ipympl.git@patch-1

@Michael-Equi
Copy link

That appears to have worked in eliminating the error although pause now seems to be preventing the rendering of my graph in my jupyter lab.

@lgtm-com
Copy link

lgtm-com bot commented Sep 26, 2020

This pull request introduces 1 alert when merging a03a5cb into 3372f9b - view on LGTM.com

new alerts:

  • 1 for Unused import

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 26, 2020

That appears to have worked in eliminating the error although pause now seems to be preventing the rendering of my graph in my jupyter lab.

But not in notebook? Do you have a short example of what you're doing?

@Michael-Equi
Copy link

I have tried running this live plot example in both Jupiter land and Jupiter notebook

import numpy as np 
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
 
 
 
def update_line(hl, new_data):
    xdata, ydata, zdata = hl._verts3d
    hl.set_xdata(np.append(xdata, new_data[0]))
    hl.set_ydata(np.append(ydata, new_data[1]))
    hl.set_3d_properties(np.append(zdata, new_data[2]))

 
 
map = plt.figure()
map_ax = Axes3D(map)
map_ax.autoscale(enable=True, axis='both', tight=True)
 
# # # Setting the axes properties
map_ax.set_xlim3d([0.0, 10.0])
map_ax.set_ylim3d([0.0, 10.0])
map_ax.set_zlim3d([0.0, 10.0])
 
hl, = map_ax.plot3D([0], [0], [0])
 
update_line(hl, (2,2, 1))
plt.draw()
plt.show(block=False)
plt.pause(1)
 
update_line(hl, (5,5, 5))
plt.show(block=False)
plt.pause(2)
 
update_line(hl, (8,1, 4))
plt.show(block=True)

In both cases it does not render the plot until the final plt.show

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 26, 2020

maybe this is similar to: #258 does the solution using async from the stackoverflow post in that issue work for you?

As for how to make your example work I think we'll need input from someone with stronger matplotlib skills than me.

@Michael-Equi
Copy link

I ended up getting it working with something like the following

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from random import randrange
from threading import Thread
import time

class LiveGraph:
    def __init__(self):
        self.x_data, self.y_data = [], []
        self.figure = plt.figure()
        self.line, = plt.plot(self.x_data, self.y_data)
        self.animation = FuncAnimation(self.figure, self.update, interval=1000)
        self.th = Thread(target=self.thread_f, daemon=True)
        self.th.start()

    def update(self, frame):
        self.line.set_data(self.x_data, self.y_data)
        self.figure.gca().relim()
        self.figure.gca().autoscale_view()
        return self.line,

    def show(self):
        plt.show()

    def thread_f(self):
        x = 0
        while True:
            self.x_data.append(x)
            x += 1
            self.y_data.append(randrange(0, 100))   
            time.sleep(1)  

g = LiveGraph()
g.show()

@martinRenou
Copy link
Member

@ianhi is this ready to be merged?

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 28, 2020

I'm not sure. It removes the error in the original issue but #266 (comment) certainly doesn't seem right and I don't think that this is expected behavior for plt.pause:

%matplotlib widget
from matplotlib import pyplot as plt

plt.figure()
plt.plot([1,2,3])
plt.pause(2)    
plt.plot([3,2,1])
plt.close()

pause

compared to the same from ipython:

pause-ipython

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 28, 2020

So basically I think this removes the error, but doesn't fix the problem. Also, I don't know how to fix the underlying problem, or even what the underlying problem is.

@martinRenou
Copy link
Member

I see. I wonder if the plt.pause() does not block the comm message. It would be interesting to see if this issue happens in the nbagg backend, see if it's a regression in ipympl.

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 28, 2020

Notebook suffers the same affliction.
pause-notebook

Since nbagg also doesn't implement the methods so I think we're falling back to the same thing. So it looks like merging this would make it so ipympl is even with nbagg, but both would be a regression from non-web backends.

@ianhi
Copy link
Collaborator Author

ianhi commented Sep 28, 2020

I think this is related to #258 which I also don't really understand.

@ianhi
Copy link
Collaborator Author

ianhi commented Jan 6, 2021

Superseded by #291

@ianhi ianhi closed this Jan 6, 2021
@ianhi ianhi deleted the patch-1 branch January 6, 2021 15:46
@martinRenou
Copy link
Member

@ianhi really sorry for this, it didn't occur to me that it was the same PR.

@ianhi
Copy link
Collaborator Author

ianhi commented Jan 6, 2021

@ianhi really sorry for this, it didn't occur to me that it was the same PR.

No worries! I had sorta left this one hanging anyways

@thomasaarholt
Copy link
Contributor

Wow, I didn't even check to see if this was here! Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plt.pause uses removed start_event_loop_default API
4 participants