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

Fix plt.pause() behaviour #291

Merged
merged 2 commits into from
Jan 6, 2021
Merged

Conversation

thomasaarholt
Copy link
Contributor

In #79, it is shown that plt.pause() raises an error when using ipympl.

%matplotlib widget
import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot([1,2,3]) # this line isn't necessary
plt.pause(1)    
# AttributeError

In that issue, there is discussion recommending removing the two methods that raise the error, as the FigureCanvasBase.start_event_loop_default method does not exist. This PR implements that.

It turns out that the ipympl Canvas object actually inherits from FigureCanvasBase anyway (through Canvas -> FigureCanvasWebAggCore -> backend_agg.FigureCanvasAgg -> FigureCanvasBase), so removing them or renaming the called methods to remove the _default are equivalent.

Here is a gif showing the new behaviour with this PR (previous was an error)

Working plt.pause()

@lgtm-com
Copy link

lgtm-com bot commented Jan 6, 2021

This pull request introduces 1 alert when merging 5079acc into f33046b - view on LGTM.com

new alerts:

  • 1 for Unused import

@martinRenou
Copy link
Member

Thanks a lot! Do you think it's also related to the other issue you opened (#290)?

There is a small flake8 issue F401 'matplotlib.backend_bases.FigureCanvasBase' imported but unused otherwise happy to merge it and make a patch release.

@martinRenou martinRenou merged commit ac0a7c3 into matplotlib:master Jan 6, 2021
@thomasaarholt
Copy link
Contributor Author

thomasaarholt commented Jan 6, 2021

I removed that import now 👍 (Edit: I see that you merged - thanks!)

This PR is related to #290, but only in fixing the behaviour of plt.pause() so that it works like sleep() does.

Do you have any idea where the "blocking" behaviour in #290 sits? I was trying to think how qt does it. :/

@martinRenou
Copy link
Member

Do you have any idea where the "blocking" behaviour in #291 sits? I was trying to think how qt does it. :/

Do you mean #290? Not sure, it looks related to other issues that are open. I think @ianhi looked at something similar concerning blocking comms or something. I suspect the comms are stuck and queued due to Matplolib, but I would need to look deeper into the code, I have to admit I never investigated this issue.

@thomasaarholt
Copy link
Contributor Author

Sorry, yes #290. It's something that I think would be really nice - currently I'm tracking whether an algorithm is converging by generating plots as it runs, but I'd have to pre-generate all the figures for it to work with ipympl.

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.

None yet

2 participants