Python matplotlib.image() Examples
The following are 30 code examples for showing how to use matplotlib.image(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example 1
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 2
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 3
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 4
Project: permute Author: statlab File: plot_directive.py License: 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 5
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: plot_directive.py License: 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 6
Project: matplotlib-4-abaqus Author: Solid-Mechanics File: pyplot.py License: 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 7
Project: matplotlib-4-abaqus Author: Solid-Mechanics File: pyplot.py License: 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 8
Project: matplotlib-4-abaqus Author: Solid-Mechanics File: pyplot.py License: 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 9
Project: neural-network-animation Author: miloharper File: pyplot.py License: 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 10
Project: neural-network-animation Author: miloharper File: pyplot.py License: 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 11
Project: neural-network-animation Author: miloharper File: pyplot.py License: 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 12
Project: GraphicDesignPatternByPython Author: Relph1119 File: plot_directive.py License: 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 13
Project: GraphicDesignPatternByPython Author: Relph1119 File: pyplot.py License: 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 14
Project: GraphicDesignPatternByPython Author: Relph1119 File: pyplot.py License: 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
Project: Visualizing-CNNs-for-monocular-depth-estimation Author: JunjH File: test.py License: MIT License | 5 votes |
def test(train_loader, model, model2, dir): totalNumber = 0 errorSum = {'MSE': 0, 'RMSE': 0, 'ABS_REL': 0, 'LG10': 0, 'MAE': 0, 'DELTA1': 0, 'DELTA2': 0, 'DELTA3': 0} model.eval() model2.eval() # if not os.path.exists(dir): # os.mkdir(dir) for i, sample_batched in enumerate(train_loader): image, depth_ = sample_batched['image'], sample_batched['depth'] image = torch.autograd.Variable(image, volatile=True).cuda() depth_ = torch.autograd.Variable(depth_, volatile=True).cuda(async=True) depth = model(image) mask = model2(image) output = model(image*mask) batchSize = depth.size(0) errors = util.evaluateError(output,depth_) errorSum = util.addErrors(errorSum, errors, batchSize) totalNumber = totalNumber + batchSize averageError = util.averageErrors(errorSum, totalNumber) # mask = mask.squeeze().view(228,304).data.cpu().float().numpy() # matplotlib.image.imsave(dir+'/mask'+str(i)+'.png', mask) print('rmse:',np.sqrt(averageError['MSE']))
Example 16
Project: SAR-change-detection Author: fouronnes File: sar_data.py License: MIT License | 5 votes |
def region(self, region): "Extract a subset of the SARData image defined by a Region object" s = SARData() s.hhhh = self.hhhh.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.hhhv = self.hhhv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.hvhv = self.hvhv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.hhvv = self.hhvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.hvvv = self.hvvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.vvvv = self.vvvv.reshape(self.shape)[np.ix_(region.range_i, region.range_j)].flatten() s.shape = (len(region.range_i), len(region.range_j)) s.size = len(region.range_i) * len(region.range_j) return s
Example 17
Project: SAR-change-detection Author: fouronnes File: sar_data.py License: MIT License | 5 votes |
def masked_region(self, mask): "Extract a subset of the SARData image defined by a mask" assert(mask.shape == self.hhhh.shape) s = SARData() for c in ["hhhh", "hhhv", "hvhv", "hhvv", "hvvv", "vvvv"]: s.__dict__[c] = self.__dict__[c][mask] s.shape = None s.size = mask.sum() return s
Example 18
Project: SAR-change-detection Author: fouronnes File: sar_data.py License: MIT License | 5 votes |
def color_composite(self): "Color composite of a EMISAR image" # Take logarithm green = 10*np.log(self.hhhh.reshape(self.shape)) / np.log(10) blue = 10*np.log(self.vvvv.reshape(self.shape)) / np.log(10) red = 10*np.log(self.hvhv.reshape(self.shape)) / np.log(10) # Normalize green = matplotlib.colors.normalize(-30, 0, clip=True)(green) blue = matplotlib.colors.normalize(-30, 0, clip=True)(blue) red = matplotlib.colors.normalize(-36, -6, clip=True)(red) # Return as a RGB image return np.concatenate((red[:,:,None], green[:,:,None], blue[:,:,None]), axis=2)
Example 19
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 20
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 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()
Example 21
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 22
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 23
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def _autogen_docstring(base): """Autogenerated wrappers will get their docstring from a base function with an addendum.""" msg = "\n\nAdditional kwargs: hold = [True|False] overrides default hold state" addendum = docstring.Appender(msg, '\n\n') return lambda func: addendum(docstring.copy_dedent(base)(func)) # This function cannot be generated by boilerplate.py because it may # return an image or a line.
Example 24
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 25
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 26
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def copper(): ''' set the default colormap to copper and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='copper') im = gci() if im is not None: im.set_cmap(cm.copper) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 27
Project: Computable Author: ktraunmueller File: pyplot.py License: 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 28
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def gray(): ''' set the default colormap to gray and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='gray') im = gci() if im is not None: im.set_cmap(cm.gray) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 29
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def hot(): ''' set the default colormap to hot and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='hot') im = gci() if im is not None: im.set_cmap(cm.hot) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example 30
Project: Computable Author: ktraunmueller File: pyplot.py License: MIT License | 5 votes |
def hsv(): ''' set the default colormap to hsv and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='hsv') im = gci() if im is not None: im.set_cmap(cm.hsv) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost