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

Non-interactive backend calls draw more than 100 times #4780

Closed
mdehoon opened this issue Jul 24, 2015 · 5 comments
Closed

Non-interactive backend calls draw more than 100 times #4780

mdehoon opened this issue Jul 24, 2015 · 5 comments

Comments

@mdehoon
Copy link
Contributor

mdehoon commented Jul 24, 2015

This code:

import matplotlib
matplotlib.use('agg')
from pylab import *
plot([1,2,5])
savefig("test")

causes Figure.draw to be called 155 times with the code currently in master.
With matplotlib 1.4.3, Figure.draw is called twice (once to create the PNG, and once to redraw the figure).
I am guessing that this has to do with the default implementation of draw_idle in FigureCanvasBase. Currently it calls draw().
So then if I change a property of the figure, the figure gets marked as stale, draw_idle is called, draw_idle calls draw, which resets the figure as non-stale.

@WeatherGod
Copy link
Member

Could this possibly be addressed by #4738?

On Fri, Jul 24, 2015 at 5:54 AM, mdehoon notifications@github.com wrote:

This code:

import matplotlib
matplotlib.use('agg')from pylab import *
plot([1,2,5])
savefig("test")

causes Figure.draw to be called 155 times with the code currently in
master.
With matplotlib 1.4.3, Figure.draw is called twice (once to create the
PNG, and once to redraw the figure).
I am guessing that this has to do with the default implementation of
draw_idle in FigureCanvasBase. Currently it calls draw().
So then if I change a property of the figure, the figure gets marked as
stale, draw_idle is called, draw_idle calls draw, which resets the figure
as non-stale.


Reply to this email directly or view it on GitHub
#4780.

@tacaswell
Copy link
Member

It is fixed by #4738 which is now a couple of changes merged together.

@mdehoon
Copy link
Contributor Author

mdehoon commented Nov 13, 2015

With 1.5.0, the example above before the call to savefig causes five calls to Figure.draw.
With the pdf, svg, and interactive backends, there is only one call to Figure.draw.

@tacaswell
Copy link
Member

This is because Agg does not actually have an asynchronous draw_idle call, just a safely re-entrant one. The extra 4 draw calls from the various figure/axes construction steps where a synchronous draw is forced every time an attribute is changed. This is a consequence of calling draw_idle on every flip to stale.

If you turn interactive mode off you will not get the extra draws (as the hook isn't installed) or if you run this in IPython (as we use their post execute hooks to get the asynchronous draw instead of relying on the backends to provide it) you will not get the extra draws.

The svg and pdf backends don't have a functional draw method (their main logic is in the print_* methods iirc).

Maybe we should raise when interactive mode is enabled with non-interactive backends, but that seems like a lot of extra complication for not much payoff.

I am in favor of closing this issue as I don't think we can do better than this in the case where

  1. interactive mode is enabled (so auto-redraw)
  2. the user is using a non-interactive backend

@mdehoon
Copy link
Contributor Author

mdehoon commented Nov 13, 2015

I don't have a strong opinion on this matter. I'm OK with closing this issue.

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

3 participants