@@ -842,34 +842,18 @@ def draw(self, drawDC=None):
842
842
self .gui_repaint (drawDC = drawDC )
843
843
844
844
def _print_image (self , filetype , filename ):
845
- origBitmap = self .bitmap
846
-
847
- self .bitmap = wx .Bitmap (math .ceil (self .figure .bbox .width ),
848
- math .ceil (self .figure .bbox .height ))
849
- renderer = RendererWx (self .bitmap , self .figure .dpi )
850
-
851
- gc = renderer .new_gc ()
852
- self .figure .draw (renderer )
853
-
854
- # image is the object that we call SaveFile on.
855
- image = self .bitmap
856
-
857
- # Now that we have rendered into the bitmap, save it to the appropriate
858
- # file type and clean up.
859
- if (cbook .is_writable_file_like (filename ) and
860
- not isinstance (image , wx .Image )):
861
- image = image .ConvertToImage ()
862
- if not image .SaveFile (filename , filetype ):
845
+ bitmap = wx .Bitmap (math .ceil (self .figure .bbox .width ),
846
+ math .ceil (self .figure .bbox .height ))
847
+ self .figure .draw (RendererWx (bitmap , self .figure .dpi ))
848
+ saved_obj = (bitmap .ConvertToImage ()
849
+ if cbook .is_writable_file_like (filename )
850
+ else bitmap )
851
+ if not saved_obj .SaveFile (filename , filetype ):
863
852
raise RuntimeError (f'Could not save figure to { filename } ' )
864
-
865
- # Restore everything to normal
866
- self .bitmap = origBitmap
867
-
868
- # Note: draw is required here since bits of state about the
869
- # last renderer are strewn about the artist draw methods. Do
870
- # not remove the draw without first verifying that these have
871
- # been cleaned up. The artist contains() methods will fail
872
- # otherwise.
853
+ # draw() is required here since bits of state about the last renderer
854
+ # are strewn about the artist draw methods. Do not remove the draw
855
+ # without first verifying that these have been cleaned up. The artist
856
+ # contains() methods will fail otherwise.
873
857
if self ._isDrawn :
874
858
self .draw ()
875
859
# The "if self" check avoids a "wrapped C/C++ object has been deleted"
0 commit comments