当前位置: 首页>>代码示例>>Python>>正文


Python cbook.open_file_cm函数代码示例

本文整理汇总了Python中matplotlib.cbook.open_file_cm函数的典型用法代码示例。如果您正苦于以下问题:Python open_file_cm函数的具体用法?Python open_file_cm怎么用?Python open_file_cm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了open_file_cm函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print_png

 def print_png(self, fname_or_fh, *args, **kwargs):
     """Use LaTeX to compile a pgf figure to pdf and convert it to png."""
     if kwargs.get("dryrun", False):
         self._print_pgf_to_fh(None, *args, **kwargs)
         return
     with cbook.open_file_cm(fname_or_fh, "wb") as file:
         self._print_png_to_fh(file, *args, **kwargs)
开发者ID:QuLogic,项目名称:matplotlib,代码行数:7,代码来源:backend_pgf.py

示例2: print_svg

    def print_svg(self, filename, *args, **kwargs):
        with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:

            filename = getattr(fh, 'name', '')
            if not isinstance(filename, six.string_types):
                filename = ''

            if cbook.file_requires_unicode(fh):
                detach = False
            else:
                if six.PY3:
                    fh = io.TextIOWrapper(fh, 'utf-8')
                else:
                    fh = codecs.getwriter('utf-8')(fh)
                detach = True

            result = self._print_svg(filename, fh, **kwargs)

            # Detach underlying stream from wrapper so that it remains open in
            # the caller.
            if detach:
                if six.PY3:
                    fh.detach()
                else:
                    fh.reset()
                    fh.stream = io.BytesIO()

        return result
开发者ID:pwuertz,项目名称:matplotlib,代码行数:28,代码来源:backend_svg.py

示例3: print_pdf

 def print_pdf(self, fname_or_fh, *args, **kwargs):
     """Use LaTeX to compile a Pgf generated figure to PDF."""
     if kwargs.get("dryrun", False):
         self._print_pgf_to_fh(None, *args, **kwargs)
         return
     with cbook.open_file_cm(fname_or_fh, "wb") as file:
         self._print_pdf_to_fh(file, *args, **kwargs)
开发者ID:QuLogic,项目名称:matplotlib,代码行数:7,代码来源:backend_pgf.py

示例4: print_pgf

 def print_pgf(self, fname_or_fh, *args, **kwargs):
     """
     Output pgf commands for drawing the figure so it can be included and
     rendered in latex documents.
     """
     if kwargs.get("dryrun", False):
         self._print_pgf_to_fh(None, *args, **kwargs)
         return
     with cbook.open_file_cm(fname_or_fh, "w", encoding="utf-8") as file:
         if not cbook.file_requires_unicode(file):
             file = codecs.getwriter("utf-8")(file)
         self._print_pgf_to_fh(file, *args, **kwargs)
开发者ID:QuLogic,项目名称:matplotlib,代码行数:12,代码来源:backend_pgf.py

示例5: print_png

    def print_png(self, filename_or_obj, *args, **kwargs):
        FigureCanvasAgg.draw(self)
        renderer = self.get_renderer()

        version_str = (
            'matplotlib version ' + __version__ + ', http://matplotlib.org/')
        metadata = OrderedDict({'Software': version_str})
        user_metadata = kwargs.pop("metadata", None)
        if user_metadata is not None:
            metadata.update(user_metadata)

        with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \
                cbook.open_file_cm(filename_or_obj, "wb") as fh:
            _png.write_png(renderer._renderer, fh,
                            self.figure.dpi, metadata=metadata)
开发者ID:DanHickstein,项目名称:matplotlib,代码行数:15,代码来源:backend_agg.py

示例6: print_png

    def print_png(self, filename_or_obj, *args, **kwargs):
        FigureCanvasAgg.draw(self)
        renderer = self.get_renderer()
        original_dpi = renderer.dpi
        renderer.dpi = self.figure.dpi

        version_str = 'matplotlib version ' + __version__ + \
            ', http://matplotlib.org/'
        metadata = OrderedDict({'Software': version_str})
        user_metadata = kwargs.pop("metadata", None)
        if user_metadata is not None:
            metadata.update(user_metadata)

        try:
            with cbook.open_file_cm(filename_or_obj, "wb") as fh:
                _png.write_png(renderer._renderer, fh,
                               self.figure.dpi, metadata=metadata)
        finally:
            renderer.dpi = original_dpi
开发者ID:mspacek,项目名称:matplotlib,代码行数:19,代码来源:backend_agg.py

示例7: print_svgz

 def print_svgz(self, filename, *args, **kwargs):
     with cbook.open_file_cm(filename, "wb") as fh, \
             gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:
         return self.print_svg(gzipwriter)
开发者ID:pwuertz,项目名称:matplotlib,代码行数:4,代码来源:backend_svg.py

示例8: print_png

    def print_png(self, filename_or_obj, *args,
                  metadata=None, pil_kwargs=None,
                  **kwargs):
        """
        Write the figure to a PNG file.

        Parameters
        ----------
        filename_or_obj : str or PathLike or file-like object
            The file to write to.

        metadata : dict, optional
            Metadata in the PNG file as key-value pairs of bytes or latin-1
            encodable strings.
            According to the PNG specification, keys must be shorter than 79
            chars.

            The `PNG specification`_ defines some common keywords that may be
            used as appropriate:

            - Title: Short (one line) title or caption for image.
            - Author: Name of image's creator.
            - Description: Description of image (possibly long).
            - Copyright: Copyright notice.
            - Creation Time: Time of original image creation
              (usually RFC 1123 format).
            - Software: Software used to create the image.
            - Disclaimer: Legal disclaimer.
            - Warning: Warning of nature of content.
            - Source: Device used to create the image.
            - Comment: Miscellaneous comment;
              conversion from other image format.

            Other keywords may be invented for other purposes.

            If 'Software' is not given, an autogenerated value for matplotlib
            will be used.

            For more details see the `PNG specification`_.

            .. _PNG specification: \
                https://www.w3.org/TR/2003/REC-PNG-20031110/#11keywords

        pil_kwargs : dict, optional
            If set to a non-None value, use Pillow to save the figure instead
            of Matplotlib's builtin PNG support, and pass these keyword
            arguments to `PIL.Image.save`.

            If the 'pnginfo' key is present, it completely overrides
            *metadata*, including the default 'Software' key.
        """
        from matplotlib import _png

        if metadata is None:
            metadata = {}
        metadata = {
            "Software":
                f"matplotlib version{__version__}, http://matplotlib.org/",
            **metadata,
        }

        if pil_kwargs is not None:
            from PIL import Image
            from PIL.PngImagePlugin import PngInfo
            buf, size = self.print_to_buffer()
            # Only use the metadata kwarg if pnginfo is not set, because the
            # semantics of duplicate keys in pnginfo is unclear.
            if "pnginfo" not in pil_kwargs:
                pnginfo = PngInfo()
                for k, v in metadata.items():
                    pnginfo.add_text(k, v)
                pil_kwargs["pnginfo"] = pnginfo
            pil_kwargs.setdefault("dpi", (self.figure.dpi, self.figure.dpi))
            (Image.frombuffer("RGBA", size, buf, "raw", "RGBA", 0, 1)
             .save(filename_or_obj, format="png", **pil_kwargs))

        else:
            FigureCanvasAgg.draw(self)
            renderer = self.get_renderer()
            with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \
                    cbook.open_file_cm(filename_or_obj, "wb") as fh:
                _png.write_png(renderer._renderer, fh,
                               self.figure.dpi, metadata=metadata)
开发者ID:matplotlib,项目名称:matplotlib,代码行数:83,代码来源:backend_agg.py


注:本文中的matplotlib.cbook.open_file_cm函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。