Python matplotlib.cm() Examples
The following are 30
code examples of matplotlib.cm().
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: test_colors.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_light_source_topo_surface(): """Shades a DEM using different v.e.'s and blend modes.""" fname = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False) dem = np.load(fname) elev = dem['elevation'] # Get the true cellsize in meters for accurate vertical exaggeration # Convert from decimal degrees to meters dx, dy = dem['dx'], dem['dy'] dx = 111320.0 * dx * np.cos(dem['ymin']) dy = 111320.0 * dy dem.close() ls = mcolors.LightSource(315, 45) cmap = cm.gist_earth fig, axes = plt.subplots(nrows=3, ncols=3) for row, mode in zip(axes, ['hsv', 'overlay', 'soft']): for ax, ve in zip(row, [0.1, 1, 10]): rgb = ls.shade(elev, cmap, vert_exag=ve, dx=dx, dy=dy, blend_mode=mode) ax.imshow(rgb) ax.set(xticks=[], yticks=[])
Example #3
Source File: pyplot.py From GraphicDesignPatternByPython 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)
Example #4
Source File: pyplot.py From neural-network-animation with MIT License | 6 votes |
def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() if hold is not None: ax.hold(hold) try: ret = ax.spy(Z, precision, marker, markersize, aspect, **kwargs) draw_if_interactive() finally: ax.hold(washold) if isinstance(ret, cm.ScalarMappable): sci(ret) return ret ################# REMAINING CONTENT GENERATED BY boilerplate.py ############## # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #5
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 #6
Source File: paper_synthetic1.py From defragTrees with MIT License | 6 votes |
def plotTZ(filename=None): cmap = cm.get_cmap('cool') fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw = {'width_ratios':[19, 1]}) ax1.add_patch(pl.Rectangle(xy=[0, 0], width=0.5, height=0.5, facecolor=cmap(0.0), linewidth='2.0')) ax1.add_patch(pl.Rectangle(xy=[0.5, 0.5], width=0.5, height=0.5, facecolor=cmap(0.0), linewidth='2.0')) ax1.add_patch(pl.Rectangle(xy=[0, 0.5], width=0.5, height=0.5, facecolor=cmap(1.0), linewidth='2.0')) ax1.add_patch(pl.Rectangle(xy=[0.5, 0], width=0.5, height=0.5, facecolor=cmap(1.0), linewidth='2.0')) ax1.set_xlabel('x1', size=22) ax1.set_ylabel('x2', size=22) ax1.set_title('True Data', size=28) colorbar.ColorbarBase(ax2, cmap=cmap, format='%.1f') ax2.set_ylabel('Output y', size=22) plt.show() if not filename is None: plt.savefig(filename, format="pdf", bbox_inches="tight") plt.close()
Example #7
Source File: paper_synthetic2.py From defragTrees with MIT License | 6 votes |
def plotTZ(filename=None): t = np.linspace(0, 1, 101) z = 0.25 + 0.5 / (1 + np.exp(- 20 * (t - 0.5))) + 0.05 * np.cos(t * 2 * np.pi) cmap = cm.get_cmap('cool') fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw = {'width_ratios':[19, 1]}) poly1 = [[0, 0]] poly1.extend([[t[i], z[i]] for i in range(t.size)]) poly1.extend([[1, 0], [0, 0]]) poly2 = [[0, 1]] poly2.extend([[t[i], z[i]] for i in range(t.size)]) poly2.extend([[1, 1], [0, 1]]) poly1 = plt.Polygon(poly1,fc=cmap(0.0)) poly2 = plt.Polygon(poly2,fc=cmap(1.0)) ax1.add_patch(poly1) ax1.add_patch(poly2) ax1.set_xlabel('x1', size=22) ax1.set_ylabel('x2', size=22) ax1.set_title('True Data', size=28) colorbar.ColorbarBase(ax2, cmap=cmap, format='%.1f') ax2.set_ylabel('Output y', size=22) plt.show() if not filename is None: plt.savefig(filename, format="pdf", bbox_inches="tight") plt.close()
Example #8
Source File: embedding_in_wx3_sgskip.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def init_plot_data(self): a = self.fig.add_subplot(111) x = np.arange(120.0) * 2 * np.pi / 60.0 y = np.arange(100.0) * 2 * np.pi / 50.0 self.x, self.y = np.meshgrid(x, y) z = np.sin(self.x) + np.cos(self.y) self.im = a.imshow(z, cmap=cm.RdBu) # , interpolation='nearest') zmax = np.max(z) - ERR_TOL ymax_i, xmax_i = np.nonzero(z >= zmax) if self.im.origin == 'upper': ymax_i = z.shape[0] - ymax_i self.lines = a.plot(xmax_i, ymax_i, 'ko') self.toolbar.update() # Not sure why this is needed - ADS
Example #9
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 #10
Source File: pyplot.py From python3_ios with BSD 3-Clause "New" or "Revised" 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 #11
Source File: pyplot.py From python3_ios with BSD 3-Clause "New" or "Revised" 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)
Example #12
Source File: pyplot.py From Computable with MIT License | 6 votes |
def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() if hold is not None: ax.hold(hold) try: ret = ax.spy(Z, precision, marker, markersize, aspect, **kwargs) draw_if_interactive() finally: ax.hold(washold) if isinstance(ret, cm.ScalarMappable): sci(ret) return ret ################# REMAINING CONTENT GENERATED BY boilerplate.py ############## # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #13
Source File: core.py From neuropythy with GNU Affero General Public License v3.0 | 6 votes |
def apply_cmap(zs, cmap, vmin=None, vmax=None, unit=None, logrescale=False): ''' apply_cmap(z, cmap) applies the given cmap to the values in z; if vmin and/or vmax are passed, they are used to scale z. Note that this function can automatically rescale data into log-space if the colormap is a neuropythy log-space colormap such as log_eccentricity. To enable this behaviour use the optional argument logrescale=True. ''' zs = pimms.mag(zs) if unit is None else pimms.mag(zs, unit) zs = np.asarray(zs, dtype='float') if pimms.is_str(cmap): cmap = matplotlib.cm.get_cmap(cmap) if logrescale: if vmin is None: vmin = np.log(np.nanmin(zs)) if vmax is None: vmax = np.log(np.nanmax(zs)) mn = np.exp(vmin) u = zdivide(nanlog(zs + mn) - vmin, vmax - vmin, null=np.nan) else: if vmin is None: vmin = np.nanmin(zs) if vmax is None: vmax = np.nanmax(zs) u = zdivide(zs - vmin, vmax - vmin, null=np.nan) u[np.isnan(u)] = -np.inf return cmap(u)
Example #14
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 6 votes |
def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() if hold is not None: ax.hold(hold) try: ret = ax.spy(Z, precision, marker, markersize, aspect, **kwargs) draw_if_interactive() finally: ax.hold(washold) if isinstance(ret, cm.ScalarMappable): sci(ret) return ret ################# REMAINING CONTENT GENERATED BY boilerplate.py ############## # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost
Example #15
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 #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 python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def spy( Z, precision=0, marker=None, markersize=None, aspect='equal', origin='upper', **kwargs): __ret = gca().spy( Z, precision=precision, marker=marker, markersize=markersize, aspect=aspect, origin=origin, **kwargs) if isinstance(__ret, cm.ScalarMappable): sci(__ret) # noqa return __ret # 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 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 #19
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 #20
Source File: pyplot.py From neural-network-animation with 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 #21
Source File: test_colors.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_colormap_copy(): cm = plt.cm.Reds cm_copy = copy.copy(cm) with np.errstate(invalid='ignore'): ret1 = cm_copy([-1, 0, .5, 1, np.nan, np.inf]) cm2 = copy.copy(cm_copy) cm2.set_bad('g') with np.errstate(invalid='ignore'): ret2 = cm_copy([-1, 0, .5, 1, np.nan, np.inf]) assert_array_equal(ret1, ret2)
Example #22
Source File: test_colors.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_colormap_endian(): """ Github issue #1005: a bug in putmask caused erroneous mapping of 1.0 when input from a non-native-byteorder array. """ cmap = cm.get_cmap("jet") # Test under, over, and invalid along with values 0 and 1. a = [-0.5, 0, 0.5, 1, 1.5, np.nan] for dt in ["f2", "f4", "f8"]: anative = np.ma.masked_invalid(np.array(a, dtype=dt)) aforeign = anative.byteswap().newbyteorder() assert_array_equal(cmap(anative), cmap(aforeign))
Example #23
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def spectral(): ''' set the default colormap to spectral and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='spectral') im = gci() if im is not None: im.set_cmap(cm.spectral) draw_if_interactive()
Example #24
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 #25
Source File: pyplot.py From neural-network-animation with 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 #26
Source File: test_colorbar.py From neural-network-animation with MIT License | 5 votes |
def test_colorbarbase(): # smoke test from #3805 ax = plt.gca() ColorbarBase(ax, plt.cm.bone)
Example #27
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 #28
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
Example #29
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 5 votes |
def spring(): ''' set the default colormap to spring and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='spring') im = gci() if im is not None: im.set_cmap(cm.spring) 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 prism(): ''' set the default colormap to prism and apply to current image if any. See help(colormaps) for more information ''' rc('image', cmap='prism') im = gci() if im is not None: im.set_cmap(cm.prism) draw_if_interactive() # This function was autogenerated by boilerplate.py. Do not edit as # changes will be lost