@@ -3316,12 +3316,37 @@ def savefig(self, fname, *, transparent=None, **kwargs):
3316
3316
3317
3317
with ExitStack () as stack :
3318
3318
if transparent :
3319
+ def _recursively_make_subfig_transparent (exit_stack , subfig ):
3320
+ exit_stack .enter_context (
3321
+ subfig .patch ._cm_set (
3322
+ facecolor = "none" , edgecolor = "none" ))
3323
+ for ax in subfig .axes :
3324
+ exit_stack .enter_context (
3325
+ ax .patch ._cm_set (
3326
+ facecolor = "none" , edgecolor = "none" ))
3327
+ for sub_subfig in subfig .subfigs :
3328
+ _recursively_make_subfig_transparent (
3329
+ exit_stack , sub_subfig )
3330
+
3331
+ def _recursively_make_axes_transparent (exit_stack , ax ):
3332
+ exit_stack .enter_context (
3333
+ ax .patch ._cm_set (facecolor = "none" , edgecolor = "none" ))
3334
+ for child_ax in ax .child_axes :
3335
+ exit_stack .enter_context (
3336
+ child_ax .patch ._cm_set (
3337
+ facecolor = "none" , edgecolor = "none" ))
3338
+ for child_childax in ax .child_axes :
3339
+ _recursively_make_axes_transparent (
3340
+ exit_stack , child_childax )
3341
+
3319
3342
kwargs .setdefault ('facecolor' , 'none' )
3320
3343
kwargs .setdefault ('edgecolor' , 'none' )
3344
+ # set subfigure to appear transparent in printed image
3345
+ for subfig in self .subfigs :
3346
+ _recursively_make_subfig_transparent (stack , subfig )
3347
+ # set axes to be transparent
3321
3348
for ax in self .axes :
3322
- stack .enter_context (
3323
- ax .patch ._cm_set (facecolor = 'none' , edgecolor = 'none' ))
3324
-
3349
+ _recursively_make_axes_transparent (stack , ax )
3325
3350
self .canvas .print_figure (fname , ** kwargs )
3326
3351
3327
3352
def ginput (self , n = 1 , timeout = 30 , show_clicks = True ,
0 commit comments