Python matplotlib.image() Examples
The following are 30
code examples of matplotlib.image().
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
, or try the search function
.
Example #1
Source File: pyplot.py From Computable with MIT License | 7 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example #2
Source File: pyplot.py From neural-network-animation with MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example #3
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 6 votes |
def clim(vmin=None, vmax=None): """ Set the color limits of the current image. To apply clim to all axes images do:: clim(0, 0.5) If either *vmin* or *vmax* is None, the image min/max respectively will be used for color scaling. If you want to set the clim of multiple images, use, for example:: for im in gca().get_images(): im.set_clim(0, 0.05) """ im = gci() if im is None: raise RuntimeError('You must first define an image, eg with imshow') im.set_clim(vmin, vmax) draw_if_interactive()
Example #4
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 6 votes |
def set_cmap(cmap): """ Set the default colormap. Applies to the current image if any. See help(colormaps) for more information. *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or the name of a registered colormap. See :func:`matplotlib.cm.register_cmap` and :func:`matplotlib.cm.get_cmap`. """ cmap = cm.get_cmap(cmap) rc('image', cmap=cmap.name) im = gci() if im is not None: im.set_cmap(cmap) draw_if_interactive()
Example #5
Source File: pyplot.py From neural-network-animation with MIT License | 6 votes |
def clim(vmin=None, vmax=None): """ Set the color limits of the current image. To apply clim to all axes images do:: clim(0, 0.5) If either *vmin* or *vmax* is None, the image min/max respectively will be used for color scaling. If you want to set the clim of multiple images, use, for example:: for im in gca().get_images(): im.set_clim(0, 0.05) """ im = gci() if im is None: raise RuntimeError('You must first define an image, e.g., with imshow') im.set_clim(vmin, vmax) draw_if_interactive()
Example #6
Source File: plot_directive.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def get_plot_formats(config): default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200} formats = [] plot_formats = config.plot_formats for fmt in plot_formats: if isinstance(fmt, str): if ':' in fmt: suffix, dpi = fmt.split(':') formats.append((str(suffix), int(dpi))) else: formats.append((fmt, default_dpi.get(fmt, 80))) elif isinstance(fmt, (tuple, list)) and len(fmt) == 2: formats.append((str(fmt[0]), int(fmt[1]))) else: raise PlotError('invalid image format "%r" in plot_formats' % fmt) return formats
Example #7
Source File: plot_directive.py From permute with BSD 2-Clause "Simplified" License | 6 votes |
def get_plot_formats(config): default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200} formats = [] plot_formats = config.plot_formats if isinstance(plot_formats, six.string_types): # String Sphinx < 1.3, Split on , to mimic # Sphinx 1.3 and later. Sphinx 1.3 always # returns a list. plot_formats = plot_formats.split(',') for fmt in plot_formats: if isinstance(fmt, six.string_types): if ':' in fmt: suffix, dpi = fmt.split(':') formats.append((str(suffix), int(dpi))) else: formats.append((fmt, default_dpi.get(fmt, 80))) elif type(fmt) in (tuple, list) and len(fmt) == 2: formats.append((str(fmt[0]), int(fmt[1]))) else: raise PlotError('invalid image format "%r" in plot_formats' % fmt) return formats
Example #8
Source File: pyplot.py From neural-network-animation with MIT License | 6 votes |
def switch_backend(newbackend): """ Switch the default backend. This feature is **experimental**, and is only expected to work switching to an image backend. e.g., if you have a bunch of PostScript scripts that you want to run from an interactive ipython session, you may want to switch to the PS backend before running them to avoid having a bunch of GUI windows popup. If you try to interactively switch from one GUI backend to another, you will explode. Calling this command will close all open windows. """ close('all') global _backend_mod, new_figure_manager, draw_if_interactive, _show matplotlib.use(newbackend, warn=False, force=True) from matplotlib.backends import pylab_setup _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
Example #9
Source File: pyplot.py From Computable with MIT License | 6 votes |
def clim(vmin=None, vmax=None): """ Set the color limits of the current image. To apply clim to all axes images do:: clim(0, 0.5) If either *vmin* or *vmax* is None, the image min/max respectively will be used for color scaling. If you want to set the clim of multiple images, use, for example:: for im in gca().get_images(): im.set_clim(0, 0.05) """ im = gci() if im is None: raise RuntimeError('You must first define an image, eg with imshow') im.set_clim(vmin, vmax) draw_if_interactive()
Example #10
Source File: plot_directive.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def get_plot_formats(config): default_dpi = {'png': 80, 'hires.png': 200, 'pdf': 200} formats = [] plot_formats = config.plot_formats for fmt in plot_formats: if isinstance(fmt, str): if ':' in fmt: suffix, dpi = fmt.split(':') formats.append((str(suffix), int(dpi))) else: formats.append((fmt, default_dpi.get(fmt, 80))) elif isinstance(fmt, (tuple, list)) and len(fmt) == 2: formats.append((str(fmt[0]), int(fmt[1]))) else: raise PlotError('invalid image format "%r" in plot_formats' % fmt) return formats
Example #11
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 6 votes |
def switch_backend(newbackend): """ Switch the default backend. This feature is **experimental**, and is only expected to work switching to an image backend. e.g., if you have a bunch of PostScript scripts that you want to run from an interactive ipython session, you may want to switch to the PS backend before running them to avoid having a bunch of GUI windows popup. If you try to interactively switch from one GUI backend to another, you will explode. Calling this command will close all open windows. """ close('all') global _backend_mod, new_figure_manager, draw_if_interactive, _show matplotlib.use(newbackend, warn=False, force=True) from matplotlib.backends import pylab_setup _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
Example #12
Source File: pyplot.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def gci(): """ Get the current colorable artist. Specifically, returns the current :class:`~matplotlib.cm.ScalarMappable` instance (image or patch collection), or *None* if no images or patch collections have been defined. The commands :func:`~matplotlib.pyplot.imshow` and :func:`~matplotlib.pyplot.figimage` create :class:`~matplotlib.image.Image` instances, and the commands :func:`~matplotlib.pyplot.pcolor` and :func:`~matplotlib.pyplot.scatter` create :class:`~matplotlib.collections.Collection` instances. The current image is an attribute of the current axes, or the nearest earlier axes in the current figure that contains an image. """ return gcf()._gci() ## Any Artist ## # (getp is simply imported)
Example #13
Source File: pyplot.py From Computable with MIT License | 6 votes |
def switch_backend(newbackend): """ Switch the default backend. This feature is **experimental**, and is only expected to work switching to an image backend. e.g., if you have a bunch of PostScript scripts that you want to run from an interactive ipython session, you may want to switch to the PS backend before running them to avoid having a bunch of GUI windows popup. If you try to interactively switch from one GUI backend to another, you will explode. Calling this command will close all open windows. """ close('all') global _backend_mod, new_figure_manager, draw_if_interactive, _show matplotlib.use(newbackend, warn=False, force=True) from matplotlib.backends import pylab_setup _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
Example #14
Source File: pyplot.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def clim(vmin=None, vmax=None): """ Set the color limits of the current image. To apply clim to all axes images do:: clim(0, 0.5) If either *vmin* or *vmax* is None, the image min/max respectively will be used for color scaling. If you want to set the clim of multiple images, use, for example:: for im in gca().get_images(): im.set_clim(0, 0.05) """ im = gci() if im is None: raise RuntimeError('You must first define an image, e.g., with imshow') im.set_clim(vmin, vmax)
Example #15
Source File: _base.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _sci(self, im): """Set the current image. This image will be the target of colormap functions like `~.pyplot.viridis`, and other functions such as `~.pyplot.clim`. The current image is an attribute of the current axes. """ if isinstance(im, matplotlib.contour.ContourSet): if im.collections[0] not in self.collections: raise ValueError("ContourSet must be in current Axes") elif im not in self.images and im not in self.collections: raise ValueError("Argument must be an image, collection, or " "ContourSet in this Axes") self._current_image = im
Example #16
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def cool(): ''' set the default colormap to cool and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='cool') im = gci() if im is not None: im.set_cmap(cm.cool) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #17
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def bone(): ''' set the default colormap to bone and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='bone') im = gci() if im is not None: im.set_cmap(cm.bone) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #18
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def autumn(): ''' set the default colormap to autumn and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='autumn') im = gci() if im is not None: im.set_cmap(cm.autumn) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #19
Source File: _base.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _update_image_limits(self, image): xmin, xmax, ymin, ymax = image.get_extent() self.axes.update_datalim(((xmin, ymin), (xmax, ymax)))
Example #20
Source File: _base.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def add_image(self, image): """ Add a :class:`~matplotlib.image.AxesImage` to the axes. Returns the image. """ self._set_artist_props(image) if not image.get_label(): image.set_label('_image%d' % len(self.images)) self.images.append(image) image._remove_method = self.images.remove self.stale = True return image
Example #21
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def figimage(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False ret = gcf().figimage(*args, **kwargs) draw_if_interactive() #sci(ret) # JDH figimage should not set current image -- it is not mappable, etc return ret
Example #22
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def colorbar(mappable=None, cax=None, ax=None, **kw): if mappable is None: mappable = gci() if mappable is None: raise RuntimeError('No mappable was found to use for colorbar ' 'creation. First define a mappable such as ' 'an image (with imshow) or a contour set (' 'with contourf).') if ax is None: ax = gca() ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw) draw_if_interactive() return ret
Example #23
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def flag(): ''' set the default colormap to flag and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='flag') im = gci() if im is not None: im.set_cmap(cm.flag) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #24
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def sci(im): """ Set the current image. This image will be the target of colormap commands like :func:`~matplotlib.pyplot.jet`, :func:`~matplotlib.pyplot.hot` or :func:`~matplotlib.pyplot.clim`). The current image is an attribute of the current axes. """ gca()._sci(im) ## Any Artist ## # (getp is simply imported)
Example #25
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def rcdefaults(): matplotlib.rcdefaults() draw_if_interactive() # The current "image" (ScalarMappable) is retrieved or set # only via the pyplot interface using the following two # functions:
Example #26
Source File: _base.py From neural-network-animation with MIT License | 5 votes |
def autoscale(self, enable=True, axis='both', tight=None): """ Autoscale the axis view to the data (toggle). Convenience method for simple axis view autoscaling. It turns autoscaling on or off, and then, if autoscaling for either axis is on, it performs the autoscaling on the specified axis or axes. *enable*: [True | False | None] True (default) turns autoscaling on, False turns it off. None leaves the autoscaling state unchanged. *axis*: ['x' | 'y' | 'both'] which axis to operate on; default is 'both' *tight*: [True | False | None] If True, set view limits to data limits; if False, let the locator and margins expand the view limits; if None, use tight scaling if the only artist is an image, otherwise treat *tight* as False. The *tight* setting is retained for future autoscaling until it is explicitly changed. Returns None. """ if enable is None: scalex = True scaley = True else: scalex = False scaley = False if axis in ['x', 'both']: self._autoscaleXon = bool(enable) scalex = self._autoscaleXon if axis in ['y', 'both']: self._autoscaleYon = bool(enable) scaley = self._autoscaleYon self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley)
Example #27
Source File: _base.py From neural-network-animation with MIT License | 5 votes |
def add_image(self, image): """ Add a :class:`~matplotlib.image.AxesImage` to the axes. Returns the image. """ self._set_artist_props(image) self.images.append(image) image._remove_method = lambda h: self.images.remove(h) return image
Example #28
Source File: _base.py From neural-network-animation with MIT License | 5 votes |
def _sci(self, im): """ helper for :func:`~matplotlib.pyplot.sci`; do not use elsewhere. """ if isinstance(im, matplotlib.contour.ContourSet): if im.collections[0] not in self.collections: raise ValueError( "ContourSet must be in current Axes") elif im not in self.images and im not in self.collections: raise ValueError( "Argument must be an image, collection, or ContourSet in " "this Axes") self._current_image = im
Example #29
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 5 votes |
def winter(): ''' set the default colormap to winter and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='winter') im = gci() if im is not None: im.set_cmap(cm.winter) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #30
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 5 votes |
def summer(): ''' set the default colormap to summer and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='summer') im = gci() if im is not None: im.set_cmap(cm.summer) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost