79296252

Date: 2024-12-20 05:22:08
Score: 0.5
Natty:
Report link

The answer is "not out of the box". There are no settings to disable redraws in the library.

Some backends might batch redraws as a side effect. The base implementation, which Agg and most others use, redraws whenever it can. The comments never claim to provide any protection from that, but leave it as an option to inheriting classes.

So it is possible to implement a custom backend with a more conservative redraw strategy and use that. In my case the following was enough:

from matplotlib.backend_bases import _Backend
from matplotlib.backends.backend_agg import FigureCanvasAgg, _BackendAgg

class FigureCanvasAggLazy(FigureCanvasAgg):
    def draw_idle(self, *args, **kwargs):
        pass # No intermediate draws needed if you are only saving to a file

@_Backend.export
class _BackendAggLazy(_BackendAgg):
    FigureCanvas = FigureCanvasAggLazy
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user2333250