|
12 | 12 | import codecs
|
13 | 13 | import atexit
|
14 | 14 | import weakref
|
| 15 | +import warnings |
15 | 16 |
|
16 | 17 | import matplotlib as mpl
|
17 | 18 | from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
|
@@ -411,12 +412,16 @@ def __init__(self, figure, fh, dummy=False):
|
411 | 412 | # get LatexManager instance
|
412 | 413 | self.latexManager = LatexManagerFactory.get_latex_manager()
|
413 | 414 |
|
414 |
| - # dummy==True deactivate all methods |
415 | 415 | if dummy:
|
| 416 | + # dummy==True deactivate all methods |
416 | 417 | nop = lambda *args, **kwargs: None
|
417 | 418 | for m in RendererPgf.__dict__.keys():
|
418 | 419 | if m.startswith("draw_"):
|
419 | 420 | self.__dict__[m] = nop
|
| 421 | + else: |
| 422 | + # if fh does not belong to a filename, deactivate draw_image |
| 423 | + if not os.path.exists(fh.name): |
| 424 | + self.__dict__["draw_image"] = lambda *args, **kwargs: None |
420 | 425 |
|
421 | 426 | def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None):
|
422 | 427 | writeln(self.fh, r"\begin{pgfscope}")
|
@@ -820,8 +825,11 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
|
820 | 825 | with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
|
821 | 826 | self._print_pgf_to_fh(fh, *args, **kwargs)
|
822 | 827 | elif is_writable_file_like(fname_or_fh):
|
823 |
| - raise ValueError("saving pgf to a stream is not supported, " + |
824 |
| - "consider using the pdf option of the pgf-backend") |
| 828 | + if not os.path.exists(fname_or_fh.name): |
| 829 | + warnings.warn("streamed pgf-code does not support raster " |
| 830 | + "graphics, consider using the pgf-to-pdf option", |
| 831 | + UserWarning) |
| 832 | + self._print_pgf_to_fh(fname_or_fh, *args, **kwargs) |
825 | 833 | else:
|
826 | 834 | raise ValueError("filename must be a path")
|
827 | 835 |
|
|
0 commit comments