Skip to content

animation blitting is no longer working #4947

Closed
@jrevans

Description

@jrevans

This is mentioned in #4897.

I currently do not have a solution for this one, but I do have a script that demonstrates the problem. I am using the current devel branch and a Qt5Agg backend.

The following is in reference to the attached script.

The line 'bg = fig.canvas.copy_from_bbox( fig.bbox )' will in fact save the current Agg buffer state as appropriate. The later calls to 'fig.canvas.restore_region( bg, fig.bbox )' however do not seem to actually restore the Agg buffers to the saved state, because in the subsequent call to 'fig.canvas.blit( fig.bbox )' the Agg buffers are still in the same state as before the call to 'restore_region'. The result is the red ellipse gets drawn multiple times to the Agg backend.

At the end of the script a new call to the canvas 'draw' method causes the entire figure to redraw (and the Agg backend), and the plot then is updated to look as expected.

======================================================================
#   blit.py
======================================================================
#!/bin/env python

import pylab as p
from matplotlib.patches import Ellipse
import math, time

p.ion()
fig, ax = p.subplots()
ax.set_xlim( [ -3, 3 ] )
ax.set_ylim( [ -3, 3 ] )

e1 = Ellipse( [ 0, 0 ], 1, 2, 0 )
ax.add_patch( e1 )

e2 = Ellipse( [ 2, 0 ], 1, 3, 0 )
ax.add_patch( e2 )

raw_input( "Press return to start blit" )

bg = fig.canvas.copy_from_bbox( fig.bbox )

e0 = Ellipse( [1,0], 1, 1, 0, facecolor="red" )
ax.add_patch( e0 )

t0 = time.time()
num = 0
while True:
   dt = time.time() - t0
   if dt > 1:
      print "%d frames in %g sec (%g frames/sec)" % ( num, dt, num/dt )
      break

   fig.canvas.restore_region( bg, fig.bbox )

   x = num / 10.0
   e0.center = [ math.cos( x ), math.sin( x ) ]

   ax.draw_artist( e0 )
   fig.canvas.blit( fig.bbox )

   num += 1


print "================="
print "Qt5 bug: red ellipse is not removed each time."
raw_input( "Press return to remove red ellipse" )

e0.remove()
fig.canvas.restore_region( bg, fig.bbox )
fig.canvas.blit( fig.bbox )

print "================="
print "The red ellipse should be gone - if it's still there, try to resize"
print "the screen.  In some cases an extra 'draw' happens here which "
print "causes the entire plot to redraw and look correct.  In Qt5agg, "
print "this shows the bug..."
print
raw_input( "Press return to exit" )

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions