@@ -176,8 +176,8 @@ def __init__(self, figure, **kwargs):
176176 self .figure = figure
177177 self .bind (size = self ._on_size_changed )
178178 super (FigureCanvasKivyAgg , self ).__init__ (figure = self .figure , ** kwargs )
179- self .img = None
180179 self .img_texture = None
180+ self .img_rect = None
181181 self .blit ()
182182
183183 def draw (self ):
@@ -201,26 +201,32 @@ def draw(self):
201201 texture = Texture .create (size = (w , h ))
202202 texture .flip_vertical ()
203203 with self .canvas :
204- Rectangle (texture = texture , pos = self .pos , size = (w , h ))
204+ self .img_rect = Rectangle (texture = texture , pos = self .pos ,
205+ size = (w , h ))
205206 texture .blit_buffer (bytes (buf_rgba ), colorfmt = 'rgba' , bufferfmt = 'ubyte' )
206207 self .img_texture = texture
207208
208209 filetypes = FigureCanvasKivy .filetypes .copy ()
209210 filetypes ['png' ] = 'Portable Network Graphics'
210211
212+ def _on_pos_changed (self , * args ):
213+ if self .img_rect is not None :
214+ self .img_rect .pos = self .pos
215+
211216 def _print_image (self , filename , * args , ** kwargs ):
212217 '''Write out format png. The image is saved with the filename given.
213218 '''
214219 l , b , w , h = self .figure .bbox .bounds
220+ img = None
215221 if self .img_texture is None :
216222 texture = Texture .create (size = (w , h ))
217223 texture .blit_buffer (bytes (self .get_renderer ().buffer_rgba ()),
218224 colorfmt = 'rgba' , bufferfmt = 'ubyte' )
219225 texture .flip_vertical ()
220- self . img = Image (texture )
226+ img = Image (texture )
221227 else :
222- self . img = Image (self .img_texture )
223- self . img .save (filename )
228+ img = Image (self .img_texture )
229+ img .save (filename )
224230
225231''' Standard names that backend.__init__ is expecting '''
226232FigureCanvas = FigureCanvasKivyAgg
0 commit comments