當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。