@@ -116,8 +116,15 @@ def _update_methods(self):
116
116
# self.draw_path_collection = self._renderer.draw_path_collection
117
117
self .draw_quad_mesh = self ._renderer .draw_quad_mesh
118
118
self .copy_from_bbox = self ._renderer .copy_from_bbox
119
- self .get_content_extents = self ._renderer .get_content_extents
120
119
120
+ @cbook .deprecated ("3.4" )
121
+ def get_content_extents (self ):
122
+ orig_img = np .asarray (self .buffer_rgba ())
123
+ slice_y , slice_x = cbook ._get_nonzero_slices (orig_img [..., 3 ])
124
+ return (slice_x .start , slice_y .start ,
125
+ slice_x .stop - slice_x .start , slice_y .stop - slice_y .start )
126
+
127
+ @cbook .deprecated ("3.4" )
121
128
def tostring_rgba_minimized (self ):
122
129
extents = self .get_content_extents ()
123
130
bbox = [[extents [0 ], self .height - (extents [1 ] + extents [3 ])],
@@ -364,23 +371,21 @@ def post_processing(image, dpi):
364
371
The saved renderer is restored and the returned image from
365
372
post_processing is plotted (using draw_image) on it.
366
373
"""
367
-
368
- width , height = int (self .width ), int (self .height )
369
-
370
- buffer , (l , b , w , h ) = self .tostring_rgba_minimized ()
374
+ orig_img = np .asarray (self .buffer_rgba ())
375
+ slice_y , slice_x = cbook ._get_nonzero_slices (orig_img [..., 3 ])
376
+ cropped_img = orig_img [slice_y , slice_x ]
371
377
372
378
self ._renderer = self ._filter_renderers .pop ()
373
379
self ._update_methods ()
374
380
375
- if w > 0 and h > 0 :
376
- img = np .frombuffer (buffer , np .uint8 )
377
- img , ox , oy = post_processing (img .reshape ((h , w , 4 )) / 255. ,
378
- self .dpi )
381
+ if cropped_img .size :
382
+ img , ox , oy = post_processing (cropped_img / 255 , self .dpi )
379
383
gc = self .new_gc ()
380
384
if img .dtype .kind == 'f' :
381
385
img = np .asarray (img * 255. , np .uint8 )
382
- img = img [::- 1 ]
383
- self ._renderer .draw_image (gc , l + ox , height - b - h + oy , img )
386
+ self ._renderer .draw_image (
387
+ gc , slice_x .start + ox , int (self .height ) - slice_y .stop + oy ,
388
+ img [::- 1 ])
384
389
385
390
386
391
class FigureCanvasAgg (FigureCanvasBase ):
0 commit comments