@@ -431,7 +431,10 @@ def __init__(self, figure, fh, dummy=False):
431
431
self .__dict__ [m ] = nop
432
432
else :
433
433
# if fh does not belong to a filename, deactivate draw_image
434
- if not os .path .exists (fh .name ):
434
+ if not hasattr (fh , 'name' ) or not os .path .exists (fh .name ):
435
+ warnings .warn ("streamed pgf-code does not support raster "
436
+ "graphics, consider using the pgf-to-pdf option" ,
437
+ UserWarning )
435
438
self .__dict__ ["draw_image" ] = lambda * args , ** kwargs : None
436
439
437
440
def draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
@@ -835,11 +838,8 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
835
838
with codecs .open (fname_or_fh , "w" , encoding = "utf-8" ) as fh :
836
839
self ._print_pgf_to_fh (fh , * args , ** kwargs )
837
840
elif is_writable_file_like (fname_or_fh ):
838
- if not os .path .exists (fname_or_fh .name ):
839
- warnings .warn ("streamed pgf-code does not support raster "
840
- "graphics, consider using the pgf-to-pdf option" ,
841
- UserWarning )
842
- self ._print_pgf_to_fh (fname_or_fh , * args , ** kwargs )
841
+ fh = codecs .getwriter ("utf-8" )(fname_or_fh )
842
+ self ._print_pgf_to_fh (fh , * args , ** kwargs )
843
843
else :
844
844
raise ValueError ("filename must be a path" )
845
845
0 commit comments