本文整理匯總了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
示例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.
示例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)
示例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)
示例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
示例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