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
matplotlib plot does not fully render if an exception is raised before cell execution completes #2166
Comments
Adding This behaves properly with ipympl (https://github.com/matplotlib/jupyter-matplotlib) import ipympl
import matplotlib.pyplot as plt
def plot_something():
plt.figure()
plt.plot([0,2],[0,2],'-')
plt.show()
plot_something()
raise Exception Need to check with @SylvainCorlay if that is ready for prime-time yet and start advertising it! |
@tacaswell - thank you for your suggestion. I upgraded matplotlib and install ipympl and it works almost as expected. The behavior I am seeing is different for the first time I run the cell and the next times. It is also different for different level of browser zoom levels (I am using Chrome 56.0.2924.87 on Windows 8.1)- First time that the cell is run -
When I rerun the cell the figure is re-rendered properly without need for resizing and independent of zoom level. Also, do you think there could be a workaround for this using matplotlib < 2.0 and nbAgg? from playing around quickly with ipympl it seems taht while it looks really great, there are still some important issues in progress. for example closing figures when clearing cell input doesn't seem to work, so it is not drop-in replacement ready just yet. Also, I am unsure how quickly I can get our codebase to upgrade to matplotlib 2.0 so a solution using matplotlib 1.5.3 would be great. |
There will be no more 1.5.x releases, so any fix would have to be locally applied. Can you report those bugs again ipympl? A vast majority of the the changes in 2.0 were style based. Unless you have some custom Image artists, it should be a smaller change than the normal minor releases (from an API point of view). |
I'm not sure what's changed in my setup (still using matplotlib 1.5.3, could be that jupyter-client was upgraded, using 4.3) but calling plt.gcf().canvas.draw() now seems to work as expected. I can even use the following in a subsequent cell to draw several figures that were left unrendered due to an exception-
I am closing the issue as I can no longer reproduce it. @tacaswell - if you can still reproduce this with some setup and think it's worthwhile to keep alive please reopen. |
@odedbd Thanks for describing the cause of the problem and a workaround! Please reopen this issue, because the problem is still there and using In my notebook I had a lot of plots and the exception was thrown in one of the last cells that I used as scratch. The plots were not rendered when I ran 'restart kernel and run all cells' command and it was absolutely not obvious what caused the problem and how to deal with it. I wanted to report the bug and found your issue.
matplotlib 2.0.2 |
I'm currently running into this issue. I'm using: I'm using It seems like there is a timing or execution speed component related to when the exception is thrown relative to when figures get drawn. I would welcome suggestions for further troubleshooting, since I'm not familiar enough with all the moving parts to make any progress. I can also provide access (privately) to a notebook server that shows this behavior if it would help diagnose this problem. |
I think this issue should be closed with no action. |
OK, thanks. |
I'd like to propose we re-open this. It does occur using |
I don't know the machinery involved very well, but it doesn't sound like there's anything to fix in IPython. Though if the ipympl or matplotlib maintainers identify a change that's needed in IPython, we can look at that. It looks like @odedbd already opened an issue for ipympl: matplotlib/ipympl#10 |
I run the following in a notebook cell:
Expected output:
Actual output:
Looking at the x,y prompt on the bottom right of the figure widget (attached screenshot) you can see that the axis range was set to [0,2] for both x & y. I have verified that by changing the plot parameters and checking that the top right corner x,y values change accordingly.
This issue is problematic when a cell executes a calculation which creates multiple figures. Any exception raised within the cell will prevent any plot from properly rendering, including the plots created before the exception was raised.
The issue is also exacerbated when the exception is raised in a following cell which gets invoked before the cell creating the plots completes execution. This is described in more detail in the SO question I posted.
I am not sure whether this belongs here or on matplotlib issues. I was unable to find a duplicate for this searching the issues for both.
Thanks!
The text was updated successfully, but these errors were encountered: