### Plot cmocean Colormap Gallery Source: http://matplotlib.org/cmocean Use this function to visualize all available cmocean colormaps. Ensure the 'plots' submodule is installed. ```python import cmocean cmocean.plots.plot_gallery() ``` -------------------------------- ### Plotting and Quick Plotting with cmocean Gray Colormap Source: http://matplotlib.org/cmocean Demonstrates how to use the cmocean.plots.test and cmocean.plots.quick_plot functions with the 'gray' colormap. This is useful for generic sequential datasets. ```python import cmocean import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 3)) ax = fig.add_subplot(1, 2, 1) cmocean.plots.test(cmocean.cm.gray, ax=ax) ax = fig.add_subplot(1, 2, 2) cmocean.plots.quick_plot(cmocean.cm.gray, ax=ax) ``` -------------------------------- ### Plotting cmocean Colormaps Source: http://matplotlib.org/cmocean Demonstrates how to plot cmocean colormaps using test and quick_plot functions. Requires importing cmocean and matplotlib.pyplot. ```python import cmocean import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 3)) ax = fig.add_subplot(1, 2, 1) cmocean.plots.test(cmocean.cm.thermal, ax=ax) ax = fig.add_subplot(1, 2, 2) cmocean.plots.quick_plot(cmocean.cm.algae, ax=ax) ``` -------------------------------- ### Generating a Colormap Dictionary Source: http://matplotlib.org/cmocean Creates a dictionary representation of a specific colormap (e.g., cmocean.cm.matter) with a specified number of entries (N). This dictionary can be used to define custom colormaps. ```python import cmocean cmdict = cmocean.tools.get_dict(cmocean.cm.matter, N=9) ``` -------------------------------- ### Plot cmocean Colormap Lightness Source: http://matplotlib.org/cmocean Visualize the lightness of cmocean colormaps to understand their perceptual properties. Requires the 'plots' submodule. ```python import cmocean cmocean.plots.plot_lightness() ``` -------------------------------- ### Plotting Reversed cmocean Colormaps Source: http://matplotlib.org/cmocean Demonstrates how to plot both a standard colormap (e.g., cmocean.cm.gray) and its reversed version (cmocean.cm.gray_r) side-by-side for comparison. Requires importing cmocean and matplotlib.pyplot. ```python import cmocean import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 3)) ax = fig.add_subplot(1, 2, 1) cmocean.plots.test(cmocean.cm.gray, ax=ax) ax = fig.add_subplot(1, 2, 2) cmocean.plots.test(cmocean.cm.gray_r, ax=ax) fig.tight_layout() ``` -------------------------------- ### Visualize Viscm Properties of a Colormap Source: http://matplotlib.org/cmocean Examine specific colormap properties like grayscale printing, perceptual deltas, and color blindness viewability using the viscm tool. Set saveplot=True to save the visualization. ```python import cmocean cmocean.plots.wrap_viscm(cmocean.cm.haline, saveplot=False) ``` -------------------------------- ### Crop One End of a Colormap by Percent Source: http://matplotlib.org/cmocean Utilize `cmocean.tools.crop_by_percent` to remove a percentage from either the maximum ('max') or minimum ('min') end of a colormap. This is helpful when certain data ranges, like super-saturated conditions, are not relevant. ```python import cmocean import matplotlib.pyplot as plt cmap = cmocean.cm.oxy fig, axes = plt.subplots(1, 2, figsize=(8,4)) A = np.random.randint(0, 101, (10,10)) mappable = axes[0].pcolormesh(A, vmin=0, vmax=100, cmap=cmap) axes[0].set_title('Values go to super-saturated') fig.colorbar(mappable, ax=axes[0]) newcmap = cmocean.tools.crop_by_percent(cmap, 20, which='max', N=None) A[A>80] = 80 mappable = axes[1].pcolormesh(A, vmin=0, vmax=80, cmap=newcmap) axes[1].set_title('Values are all\nbelow super-saturated') fig.colorbar(mappable, ax=axes[1]) ``` -------------------------------- ### Accessing cmocean Colormap Dictionary Source: http://matplotlib.org/cmocean Loads a dictionary containing all available colormap instances from the cmocean.cm module. This dictionary can be used to access colormaps by name. ```python import cmocean cmocean.cm.cmap_d ``` -------------------------------- ### Crop Colormap by Data Values Source: http://matplotlib.org/cmocean Employ `cmocean.tools.crop` to clip a colormap based on the minimum and maximum data values intended for plotting. This ensures the colormap range accurately reflects the data's extent, useful for combined datasets like bathymetry and topography. ```python import cmocean import matplotlib.pyplot as plt cmap = cmocean.cm.topo fig, axes = plt.subplots(1, 2, figsize=(8,4)) A = np.random.randint(-50, 201, (10,10)) mappable = axes[0].pcolormesh(A, vmin=-200, vmax=200, cmap=cmap) axes[0].set_title('No values<-50, but still\nshow possibility in colorbar') fig.colorbar(mappable, ax=axes[0]) newcmap = cmocean.tools.crop(cmap, -50, 200, 0) mappable = axes[1].pcolormesh(A, vmin=-50, vmax=200, cmap=newcmap) axes[1].set_title('Colorbar only shows color\nrange used by data') fig.colorbar(mappable, ax=axes[1]) ``` -------------------------------- ### Crop Both Ends of a Colormap by Percent Source: http://matplotlib.org/cmocean Use `cmocean.tools.crop_by_percent` to remove a specified percentage from both ends of a colormap. This is useful for reducing the lightness range and excluding extreme values. ```python import cmocean import matplotlib.pyplot as plt cmap = cmocean.cm.tarn fig, axes = plt.subplots(1, 2, figsize=(8,4)) A = np.random.randint(-5, 6, (10,10)) mappable = axes[0].pcolormesh(A, cmap=cmap) axes[0].set_title('Full diverging colormap') fig.colorbar(mappable, ax=axes[0]) newcmap = cmocean.tools.crop_by_percent(cmap, 30, which='both', N=None) mappable = axes[1].pcolormesh(A, cmap=newcmap) axes[1].set_title('Same colormap,\n30% removed from each end') fig.colorbar(mappable, ax=axes[1]) ``` -------------------------------- ### Using Registered cmocean Colormaps in Matplotlib Source: http://matplotlib.org/cmocean Illustrates how cmocean colormaps are registered with matplotlib, allowing them to be called directly by their registered name (e.g., 'cmo.amp'). Requires importing cmocean and matplotlib.pyplot, and numpy. ```python import cmocean import matplotlib.pyplot as plt fig = plt.figure(figsize=(4, 3)) ax = fig.add_subplot(111) Z = np.random.randn(10,10) ax.pcolormesh(Z, cmap='cmo.amp') ``` -------------------------------- ### Lightening cmocean Colormaps Source: http://matplotlib.org/cmocean Shows how to lighten a colormap using the cmocean.tools.lighten() function with an alpha value. This is useful for overlaying contours or lines on plots. Requires importing cmocean, cmocean.cm, and matplotlib.pyplot, and numpy. ```python import cmocean import cmocean.cm as cmo import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(8, 3)) ax = fig.add_subplot(1, 2, 1) Z = np.random.randn(10,10) ax.pcolormesh(Z, cmap=cmo.matter) ax = fig.add_subplot(1, 2, 2) lightcmap = cmocean.tools.lighten(cmo.matter, 0.5) ax.pcolormesh(Z, cmap=lightcmap) fig.tight_layout() ``` -------------------------------- ### Accessing cmocean Colormap Names Source: http://matplotlib.org/cmocean Retrieves a list of all available colormap names from the cmocean.cm module. This is useful for iterating through or selecting specific colormaps. ```python import cmocean cmocean.cm.cmapnames ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.