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


Python backend_bases.FigureCanvasBase方法代码示例

本文整理汇总了Python中matplotlib.backend_bases.FigureCanvasBase方法的典型用法代码示例。如果您正苦于以下问题:Python backend_bases.FigureCanvasBase方法的具体用法?Python backend_bases.FigureCanvasBase怎么用?Python backend_bases.FigureCanvasBase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backend_bases的用法示例。


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

示例1: _canvas_to_bytes

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def _canvas_to_bytes(canvas: "FigureCanvasBase") -> ByteBuffer:
        pass 
开发者ID:corrscope,项目名称:corrscope,代码行数:4,代码来源:renderer.py

示例2: _redraw_over_background

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def _redraw_over_background(self) -> None:
        """ Redraw animated elements of the image. """

        # Both FigureCanvasAgg and FigureCanvasCairo, but not FigureCanvasBase,
        # support restore_region().
        canvas: FigureCanvasAgg = self._fig.canvas
        canvas.restore_region(self.bg_cache)

        for artist in self._artists:
            artist.axes.draw_artist(artist)

        # canvas.blit(self._fig.bbox) is unnecessary when drawing off-screen. 
开发者ID:corrscope,项目名称:corrscope,代码行数:14,代码来源:renderer.py

示例3: test_get_default_filename

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def test_get_default_filename():
    try:
        test_dir = tempfile.mkdtemp()
        plt.rcParams['savefig.directory'] = test_dir
        fig = plt.figure()
        canvas = FigureCanvasBase(fig)
        filename = canvas.get_default_filename()
        assert filename == 'image.png'
    finally:
        shutil.rmtree(test_dir) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:12,代码来源:test_backend_bases.py

示例4: test_get_default_filename_already_exists

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def test_get_default_filename_already_exists():
    # From #3068: Suggest non-existing default filename
    try:
        test_dir = tempfile.mkdtemp()
        plt.rcParams['savefig.directory'] = test_dir
        fig = plt.figure()
        canvas = FigureCanvasBase(fig)

        # create 'image.png' in figure's save dir
        open(os.path.join(test_dir, 'image.png'), 'w').close()

        filename = canvas.get_default_filename()
        assert filename == 'image-1.png'
    finally:
        shutil.rmtree(test_dir) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:17,代码来源:test_backend_bases.py

示例5: thumbnail

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
              preview=False):
    """
    Make a thumbnail of image in *infile* with output filename *thumbfile*.

    See :doc:`/gallery/misc/image_thumbnail_sgskip`.

    Parameters
    ----------
    infile : str or file-like
        The image file -- must be PNG, or Pillow-readable if you have Pillow_
        installed.

        .. _Pillow: http://python-pillow.org/

    thumbfile : str or file-like
        The thumbnail filename.

    scale : float, optional
        The scale factor for the thumbnail.

    interpolation : str, optional
        The interpolation scheme used in the resampling. See the
        *interpolation* parameter of `~.Axes.imshow` for possible values.

    preview : bool, optional
        If True, the default backend (presumably a user interface
        backend) will be used which will cause a figure to be raised if
        `~matplotlib.pyplot.show` is called.  If it is False, the figure is
        created using `FigureCanvasBase` and the drawing backend is selected
        as `~matplotlib.figure.savefig` would normally do.

    Returns
    -------
    figure : `~.figure.Figure`
        The figure instance containing the thumbnail.
    """

    im = imread(infile)
    rows, cols, depth = im.shape

    # This doesn't really matter (it cancels in the end) but the API needs it.
    dpi = 100

    height = rows / dpi * scale
    width = cols / dpi * scale

    if preview:
        # Let the UI backend do everything.
        import matplotlib.pyplot as plt
        fig = plt.figure(figsize=(width, height), dpi=dpi)
    else:
        from matplotlib.figure import Figure
        fig = Figure(figsize=(width, height), dpi=dpi)
        FigureCanvasBase(fig)

    ax = fig.add_axes([0, 0, 1, 1], aspect='auto',
                      frameon=False, xticks=[], yticks=[])
    ax.imshow(im, aspect='auto', resample=True, interpolation=interpolation)
    fig.savefig(thumbfile, dpi=dpi)
    return fig 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:63,代码来源:image.py

示例6: thumbnail

# 需要导入模块: from matplotlib import backend_bases [as 别名]
# 或者: from matplotlib.backend_bases import FigureCanvasBase [as 别名]
def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
              preview=False):
    """
    Make a thumbnail of image in *infile* with output filename *thumbfile*.

    See :doc:`/gallery/misc/image_thumbnail_sgskip`.

    Parameters
    ----------
    infile : str or file-like
        The image file -- must be PNG, Pillow-readable if you have `Pillow
        <http://python-pillow.org/>`_ installed.

    thumbfile : str or file-like
        The thumbnail filename.

    scale : float, optional
        The scale factor for the thumbnail.

    interpolation : str, optional
        The interpolation scheme used in the resampling. See the
        *interpolation* parameter of `~.Axes.imshow` for possible values.

    preview : bool, optional
        If True, the default backend (presumably a user interface
        backend) will be used which will cause a figure to be raised if
        `~matplotlib.pyplot.show` is called.  If it is False, the figure is
        created using `FigureCanvasBase` and the drawing backend is selected
        as `~matplotlib.figure.savefig` would normally do.

    Returns
    -------
    figure : `~.figure.Figure`
        The figure instance containing the thumbnail.
    """

    im = imread(infile)
    rows, cols, depth = im.shape

    # This doesn't really matter (it cancels in the end) but the API needs it.
    dpi = 100

    height = rows / dpi * scale
    width = cols / dpi * scale

    if preview:
        # Let the UI backend do everything.
        import matplotlib.pyplot as plt
        fig = plt.figure(figsize=(width, height), dpi=dpi)
    else:
        from matplotlib.figure import Figure
        fig = Figure(figsize=(width, height), dpi=dpi)
        FigureCanvasBase(fig)

    ax = fig.add_axes([0, 0, 1, 1], aspect='auto',
                      frameon=False, xticks=[], yticks=[])
    ax.imshow(im, aspect='auto', resample=True, interpolation=interpolation)
    fig.savefig(thumbfile, dpi=dpi)
    return fig 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:61,代码来源:image.py


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