Python matplotlib.backend_bases.FigureCanvasBase() Examples
The following are 9
code examples of matplotlib.backend_bases.FigureCanvasBase().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.backend_bases
, or try the search function
.
Example #1
Source File: renderer.py From corrscope with BSD 2-Clause "Simplified" License | 5 votes |
def _canvas_to_bytes(canvas: "FigureCanvasBase") -> ByteBuffer: pass
Example #2
Source File: renderer.py From corrscope with BSD 2-Clause "Simplified" License | 5 votes |
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.
Example #3
Source File: test_backend_bases.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #4
Source File: test_backend_bases.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #5
Source File: image.py From Mastering-Elasticsearch-7.0 with MIT License | 4 votes |
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
Example #6
Source File: image.py From GraphicDesignPatternByPython with MIT License | 4 votes |
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
Example #7
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example #8
Source File: image.py From coffeegrindsize with MIT License | 4 votes |
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
Example #9
Source File: image.py From CogAlg with MIT License | 4 votes |
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