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

notebook with pylab=inline appears to call figure.draw twice #3127

Closed
bicubic opened this issue Apr 3, 2013 · 3 comments
Closed

notebook with pylab=inline appears to call figure.draw twice #3127

bicubic opened this issue Apr 3, 2013 · 3 comments
Milestone

Comments

@bicubic
Copy link

bicubic commented Apr 3, 2013

I had to hook matplotlib.Figure.draw for unrelated reasons and noticed it gets called twice in ipython notebook. Is this intentional?

Tracing through all method calls on figure, I found that a plain python script will call

clf
set_canvas
add_axobserver
add_subplot
sca
set_size_inches
draw
get_rasterized
get_agg_filter
get_visible
get_agg_filter
get_rasterized

While notebook will call

clf
set_canvas
add_subplot
sca
get_facecolor
get_edgecolor
set_facecolor
set_edgecolor
get_facecolor
get_edgecolor
set_facecolor
set_edgecolor
draw
get_rasterized
get_agg_filter
get_visible
get_agg_filter
get_rasterized
get_tightbbox
draw
get_rasterized
get_agg_filter
get_visible
get_agg_filter
get_rasterized
set_facecolor
set_edgecolor
set_canvas
set_facecolor
set_edgecolor

You can run https://gist.github.com/tricubic/0d33d808a0d7fa7dbf22 in notebook or as a script to repeat this.

@Carreau
Copy link
Member

Carreau commented Apr 3, 2013

Did you changed your username ?

https://gist.github.com/tricubic/0d33d808a0d7fa7dbf22

@bicubic
Copy link
Author

bicubic commented Apr 3, 2013

Hah, sorry I did. Updated the link.

@bicubic
Copy link
Author

bicubic commented Apr 3, 2013

This turns out to be intended, although unpleasant behavior of matplotlib\backend_bases.py:

"when bbox_inches == "tight", it saves the figure
twice. The first save command is just to estimate
the bounding box of the figure. A stringIO object is
used as a temporary file object, but it causes a
problem for some backends (ps backend with
usetex=True) if they expect a filename, not a
file-like object. As I think it is best to change
the backend to support file-like object, i'm going
to leave it as it is. However, a better solution
than stringIO seems to be needed. -JJL
result = getattr(self, method_name)"

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

No branches or pull requests

2 participants