### Install CMasher from source Source: https://github.com/1313e/cmasher/blob/master/README.rst Clones the CMasher repository and installs it manually using pip. ```bash $ git clone https://github.com/1313e/CMasher $ cd CMasher $ pip install . ``` -------------------------------- ### Install RColorBrewer package Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst Installs the RColorBrewer package if it is not already installed. ```R # If RColorBrewer is not already installed, install it with: install.packages('RColorBrewer') ``` -------------------------------- ### Install CMasher with pip Source: https://github.com/1313e/cmasher/blob/master/README.rst Installs the CMasher package from PyPI using pip. ```bash $ pip install cmasher ``` -------------------------------- ### Check CMasher CLI availability Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/app_usage/Tableau.rst Run `cmr` to verify that CMasher's CLI tools are installed. If the command is not recognized, CMasher is not installed. ```default $ cmr ``` -------------------------------- ### Create a sub-colormap Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Examples of creating a sub-colormap from an existing colormap using a range or a specific number of segments. ```default >>> get_sub_cmap('cmr.rainforest', 0, 0.8) ``` ```pycon >>> get_sub_cmap('cmr.lilac', 0.2, 0.8, N=5) ``` -------------------------------- ### Install CMasher with conda Source: https://github.com/1313e/cmasher/blob/master/README.rst Installs CMasher from conda-forge. The first command is used if conda-forge is not set up as a channel; the second if it is already configured. ```bash $ conda install -c conda-forge cmasher # If conda-forge is not set up as a channel $ conda install cmasher # If conda-forge is set up as a channel ``` -------------------------------- ### Create and view a sub-colormap with get_sub_cmap and view_cmap Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/usage.rst Use cmasher.get_sub_cmap() to create a qualitative sub-colormap from 'cmr.lilac' with 5 discrete colors between 0.2 and 0.8, then display it with cmasher.view_cmap(). This example is used to generate the qualitative sub-colormap shown in Fig. 10. ```python # Import CMasher import cmasher as cmr # Create sub-colormap cmap = cmr.get_sub_cmap('cmr.lilac', 0.2, 0.8, N=5) # View colormap cmr.view_cmap(cmap) ``` -------------------------------- ### Redirect CLI output to a file: cmr rgbtable Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/usage.rst Redirects the output of the `cmr rgbtable` command to a file on UNIX systems. The example saves the RGB values of the 'rainforest' colormap to a `.txt` file. ```bash cmr rgbtable cmr.rainforest > rainforest.txt ``` -------------------------------- ### Get colormap type via object path: cmr cmtype Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/usage.rst Requests the colormap type of the 'rainforest' colormap using the object path format `'a.b:c.d'`. The example shows two equivalent module paths: `cmasher:rainforest` and `cmasher.cm:rainforest`. ```bash cmr cmtype cmasher:rainforest ``` ```bash cmr cmtype cmasher.cm:rainforest ``` -------------------------------- ### Take 5 colors from a colormap with take_cmap_colors() Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/usage.rst Uses cmr.take_cmap_colors() to extract 5 equally spaced colors from the 'cmr.rainforest' colormap in the range [0.15, 0.85] and returns them in HEX format. The colors are then used to create 5 line plots, with axes hidden and a legend displayed. This example demonstrates the function's usage for high perceptual range colormaps like rainforest. ```python # Import packages import cmasher as cmr import matplotlib.pyplot as plt import numpy as np # Create figure object fig = plt.figure() # Take 5 colors from rainforest in [0.15, 0.85] range in HEX colors = cmr.take_cmap_colors('cmr.rainforest', 5, cmap_range=(0.15, 0.85), return_fmt='hex') # Create 5 line plots, each using a different color for i, color in enumerate(colors): x = 0.1*(i+1)*np.linspace(0, 1, 100)**2 plt.plot(x, color=color, label=color) # Obtain axes object ax = fig.axes[0] # Turn off the X and Y axes ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) # Create legend ax.legend(loc='upper left') # Show figure plt.show() ``` -------------------------------- ### Add a colormap legend entry to a hexbin plot Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/usage.rst This example creates a hexbin plot with the 'cmr.rainforest' colormap and adds a legend entry using cmr.set_cmap_legend_entry(). It then adjusts the axes and displays the plot. The legend entry is added to the plot's legend. ```python # Import packages import cmasher as cmr import matplotlib.pyplot as plt import numpy as np # Create figure object fig = plt.figure() # Generate some data to plot x = np.random.rand(1000000) y = np.random.rand(1000000) z = x**2+y**2 # Create hexbin plot using the rainforest colormap plot = plt.hexbin(x, y, z, 50, cmap='cmr.rainforest') # Add legend entry cmr.set_cmap_legend_entry(plot, 'rainforest') # Obtain axes object ax = fig.axes[0] # Set axes limits ax.axis([0, 1, 0, 1]) # Turn off the X and Y axes ax.set_axis_off() ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) # Create legend ax.legend(loc='upper left') # Show figure plt.show() ``` -------------------------------- ### cmasher.get_sub_cmap(cmap: Colormap | Name, start: float, stop: float, N: int | None = None) -> ListedColormap Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Creates a ListedColormap object using the colors in the range [start, stop] of the provided cmap and returns it. This function can be used to create a colormap that only uses a portion of an existing colormap. If N is not set to None, this function creates a qualitative colormap from cmap instead. ```APIDOC ## cmasher.get_sub_cmap(cmap: Colormap | Name, start: float, stop: float, N: int | None = None) -> ListedColormap ### Description Creates a ListedColormap object using the colors in the range [start, stop] of the provided cmap and returns it. This function can be used to create a colormap that only uses a portion of an existing colormap. If N is not set to None, this function creates a qualitative colormap from cmap instead. ### Parameters - **cmap** (str or Colormap object) - Required - The registered name of the colormap in matplotlib.cm or its corresponding Colormap object. - **start** (float) - Required - The normalized start of the range of colors in cmap that must be in the sub-colormap. - **stop** (float) - Required - The normalized end of the range of colors in cmap that must be in the sub-colormap. - **N** (int or None, default: None) - Optional - The number of color segments to take from the provided cmap within the range given by the provided start and stop. If None, take all colors in cmap within this range. ### Returns - **sub_cmap** (ListedColormap) - The created colormap that uses a subset of the colors in cmap. If N is not None, this will be a qualitative colormap. ### Example Creating a colormap using the first 80% of the 'rainforest' colormap: ```default >>> get_sub_cmap('cmr.rainforest', 0, 0.8) ``` Creating a qualitative colormap containing five colors from the middle 60% of the 'lilac' colormap: ```pycon >>> get_sub_cmap('cmr.lilac', 0.2, 0.8, N=5) ``` ``` -------------------------------- ### Create colormap overview with cmr.create_cmap_overview Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/cmap_overviews/cmr_cmaps.rst Generates a visual overview of all available CMasher colormaps, sorted by perceptual profile and including perceptual information. ```python # Import packages import cmasher as cmr # Create colormap overview of all colormaps in CMasher cmr.create_cmap_overview(sort='perceptual', show_info=True) ``` -------------------------------- ### Create overview of single major color colormaps with cmr.create_cmap_overview Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/cmap_overviews/single_major.rst Imports the cmasher package, defines a list of single-major-color colormaps (e.g., flamingo, ember, sunburst), and calls cmr.create_cmap_overview with use_types=False, sort=None, show_grayscale=False, and wscale=2 to generate the overview plot. ```python # Import packages import cmasher as cmr # Create list with single major color colormaps cmaps_lst = [ cmr.flamingo, cmr.ember, cmr.sunburst, cmr.amber, cmr.sepia, cmr.jungle, cmr.nuclear, cmr.emerald, cmr.swamp, cmr.ocean, cmr.arctic, cmr.sapphire, cmr.freeze, cmr.cosmic, cmr.amethyst, cmr.gothic, cmr.neutral] # Create colormap overview of selected colormaps with no grayscale subplots cmr.create_cmap_overview(cmaps_lst, use_types=False, sort=None, show_grayscale=False, wscale=2) ``` -------------------------------- ### Create categorized colormap overview with cmasher Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/cmap_overviews/categories.rst This snippet imports cmasher, defines a dictionary of colormap categories (Blue, Seasons, Nature) with specific colormaps, and calls cmr.create_cmap_overview with sort=None and dark_mode=True to generate the overview. The categories were determined at v1.4.0. ```python # Import packages import cmasher as cmr # Create dict with a few specific categories for colormaps cmaps_dct = { 'Blue': [ 'cmr.arctic', 'cmr.freeze', 'cmr.ocean', 'PuBu', 'Blues'], 'Seasons': [ 'cmr.fall', 'summer', 'autumn', 'spring', 'winter'], 'Nature': [ 'cmr.lavender', 'cmr.dusk', 'cmr.amber', 'cmr.eclipse', 'cmr.apple', 'cmr.arctic', 'cmr.flamingo', 'cmr.jungle', 'cmr.rainforest', 'cmr.savanna', 'cmr.sunburst', 'cmr.swamp', 'bone', 'cmr.fall', 'cmr.ocean', 'cmr.horizon', 'inferno', 'magma', 'cmr.pepper', 'plasma', 'summer', 'autumn', 'spring', 'winter', 'cmr.redshift', 'cmr.watermelon', 'Spectral', 'seismic', 'cmr.fusion', 'cmr.viola', 'cmr.waterlily', 'cmr.wildfire', 'twilight', 'ocean', 'rainbow', 'terrain', 'cool', 'hot']} # Create colormap overview of selected colormaps, divided into categories cmr.create_cmap_overview(cmaps_dct, sort=None, dark_mode=True) ``` -------------------------------- ### create_cmap_overview() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Creates an overview of colormaps. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## create_cmap_overview() ### Description Creates an overview of colormaps. ### Method Function call ### Endpoint cmasher.create_cmap_overview ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### Create colormap overview with cmasher Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/cmap_overviews/mpl_cmaps.rst Use this snippet to generate a colormap overview of all matplotlib colormaps, including their lightness profiles, sorted by lightness. Requires the cmasher and matplotlib packages. ```python # Import packages import cmasher as cmr import matplotlib.pyplot as plt # Obtain list of all colormaps in MPL cmaps = plt.colormaps() # Create colormap overview of all colormaps in MPL cmr.create_cmap_overview(cmaps, plot_profile=True, sort='lightness') ``` -------------------------------- ### Create sequential colormap overview with CMasher Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/cmap_overviews/seq_mpl_cmaps.rst Imports cmasher and matplotlib, filters all sequential colormaps from matplotlib and CMasher, and creates a colormap overview with a custom title. ```python # Import packages import cmasher as cmr import matplotlib.pyplot as plt # Obtain all colormaps in MPL and CMasher that are sequential cmaps = [cmap for cmap in plt.colormaps() if cmr.get_cmap_type(cmap) == 'sequential'] # Create colormap overview of all sequential colormaps in MPL and CMasher cmr.create_cmap_overview(cmaps, use_types=False, title="Sequential MPL Colormaps") ``` -------------------------------- ### Clone the CMasher repository Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst Clones the CMasher repository from GitHub. Run this command in a terminal. ```default $ git clone https://github.com/1313e/CMasher ``` -------------------------------- ### Create or update Tableau preferences file with CLI Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/app_usage/Tableau.rst Navigate to the Tableau directory and run `cmr app_usage tableau` to create a new preferences file or update an existing one, adding all CMasher colormaps without modifying other content. The command automatically detects changes or renames of colormaps and outputs a confirmation message. ```default $ cd /path/to/Tableau/directory $ cmr app_usage tableau Created/Updated Tableau preferences file in '/path/to/Tableau/directory'. ``` -------------------------------- ### Import custom colormaps Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Importing a custom colormap from a file and accessing it via CMasher or Matplotlib. ```pycon >>> import_cmaps('/path/to/dir/cm_test.txt') ``` ```pycon >>> cmr.cm.test # CMasher >>> plt.get_cmap('cmr.test') # MPL ``` -------------------------------- ### Create or update Tableau preferences file with Python Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/app_usage/Tableau.rst Use the `update_tableau_pref_file()` function from CMasher to perform the same action as the CLI command, passing the path to the Tableau directory. ```python >>> import cmasher as cmr >>> cmr.app_usage.update_tableau_pref_file("/path/to/Tableau/directory") ``` -------------------------------- ### Create RDS object with all CMasher colormaps Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst Loads all CMasher colormaps into an RDS object for future use. Requires editing the colormaps_path and RDSfilepath variables. Run once and whenever new colormaps are added. ```R # Loading RColorBrewer package. library(RColorBrewer) # Edit following paths: colormaps_path = './CMasher/cmasher/colormaps' RDSfilepath = '/path/to/where/you/wanna/keep/the/RDS/object' # Looking up the names of the scales and location of the _norm.txt files: cmr_cmaps_files = list.files(path=colormaps_path, recursive=TRUE, all.files=TRUE, full.name=TRUE, pattern='_norm.txt') cmr_cmaps_list = list.dirs(path=colormaps_path, full.names=FALSE) cmr_cmaps_list = cmr_cmaps_list[2:length(cmr_cmaps_list)] # Removing "." from the list of directories # Loading all colour scales and adding them to a list object containing all scales called cmr_cmaps. cmr_cmaps = list() for (cmr_cmap in cmr_cmaps_list) { CM_RGB = read.table(file=cmr_cmaps_files[grep(pattern=cmr_cmap, cmr_cmaps_list)]) colnames(CM_RGB) = c('R', 'G', 'B') assign(cmr_cmap, rgb(red=CM_RGB$R, green=CM_RGB$G, blue=CM_RGB$B)) cmr_cmaps[[cmr_cmap]] = get(cmr_cmap) } # Create RDS file containing all CMasher colormaps into a single object: saveRDS(cmr_cmaps, file=paste0(RDSfilepath, '/', 'cmr_cmaps.RDS')) ``` -------------------------------- ### Create a standalone colormap module Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Generate a standalone Python module for a registered CMasher colormap to allow usage without the CMasher dependency. ```default >>> create_cmap_mod('rainforest') ``` -------------------------------- ### Combine colormaps using predefined names Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Create a composite colormap by passing a list of colormap names and optional blending nodes. ```pycon >>> custom_cmap_1 = combine_cmaps( ["ocean", "prism", "coolwarm"], nodes=[0.2, 0.75] ) ``` -------------------------------- ### cmasher.create_cmap_mod Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Creates a standalone Python module of a provided CMasher colormap and saves it in the given directory. The generated module can be imported without the CMasher dependency. ```APIDOC ## cmasher.create_cmap_mod ### Description Creates a standalone Python module of the provided CMasher colormap and saves it in the given save_dir as '.py'. The standalone module can be used to share a colormap without adding the CMasher dependency. ### Signature cmasher.create_cmap_mod(cmap: Name, save_dir: str | os.PathLike[str] = '.', _copy_name: str | None = None) -> str ### Parameters - **cmap** (*str*) - Required - The name of the CMasher colormap a standalone Python module must be made for. An added 'cmr.' prefix will be ignored. - **save_dir** (*str or os.PathLike[str]*) - Optional - The path to the directory where the module must be saved. Defaults to the current directory ('.'). ### Returns - **cmap_path** (*str*) - The path to the Python file containing the colormap module. ### Example Creating a standalone Python module of the 'rainforest' colormap: ```default >>> create_cmap_mod('rainforest') ``` One can now import the 'rainforest' colormap in any script by moving the created 'rainforest.py' file to the proper working directory and importing it with `import rainforest`. ``` -------------------------------- ### cmasher.set_cmap_legend_entry(artist: Artist, label: str) -> None Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Sets the label of the provided artist to label, and creates a legend entry using a miniature version of the colormap of artist as the legend icon. This function can be used to add legend entries for MPL artists that use a colormap, like those made with hexbin(); hist2d(); scatter(); or any pyplot function that takes cmap as an input argument. Keep in mind that using this function will override any legend entry that already exists for artist. ```APIDOC ## cmasher.set_cmap_legend_entry(artist: Artist, label: str) -> None ### Description Sets the label of the provided artist to label, and creates a legend entry using a miniature version of the colormap of artist as the legend icon. This function can be used to add legend entries for MPL artists that use a colormap, like those made with hexbin(); hist2d(); scatter(); or any pyplot function that takes cmap as an input argument. Keep in mind that using this function will override any legend entry that already exists for artist. ### Parameters - **artist** (Artist object) - Required - Any artist object that has the cmap attribute, for which a legend entry must be made using its colormap as the icon. - **label** (str) - Required - The string that must be set as the label of artist. ``` -------------------------------- ### cmasher.get_bibtex Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Prints a string that gives the BibTeX entry for citing the CMasher paper (Van der Velden 2020, JOSS, 5, 2004). ```APIDOC ## Function: cmasher.get_bibtex ### Description Prints a string that gives the BibTeX entry for citing the CMasher paper (Van der Velden 2020, JOSS, 5, 2004). ### Signature cmasher.get_bibtex() -> None ### Parameters None ### Returns None ``` -------------------------------- ### Load CMasher colormaps from RDS object Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst Loads the previously created RDS object into any R project. Requires setting the RDSfilepath variable. ```R # Easy to load using the RDS object back into any R project using: RDSfilepath = '/path/to/where/you/wanna/keep/the/RDS/object' cmr_cmaps = readRDS(file=paste0(RDSfilepath, '/', 'cmr_cmaps.RDS')) ``` -------------------------------- ### cmasher.import_cmaps(cmap_path: str | os.PathLike[str], _skip_registration: bool = False) -> None Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Reads in custom colormaps from a provided file or directory cmap_path; transforms them into ListedColormap objects; and makes them available in the cmasher.cm module, in addition to registering them in the matplotlib.cm module. Both the imported colormap and its reversed version will be registered. If a provided colormap is a 'cyclic' colormap, its shifted version will also be registered with the _s suffix. ```APIDOC ## cmasher.import_cmaps(cmap_path: str | os.PathLike[str], _skip_registration: bool = False) -> None ### Description Reads in custom colormaps from a provided file or directory cmap_path; transforms them into ListedColormap objects; and makes them available in the cmasher.cm module, in addition to registering them in the matplotlib.cm module. Both the imported colormap and its reversed version will be registered. If a provided colormap is a 'cyclic' colormap, its shifted version will also be registered with the _s suffix. ### Parameters - **cmap_path** (str or os.PathLike[str]) - Required - Relative or absolute path to a custom colormap file; or directory that contains custom colormap files. A colormap file can be a NumPy binary file ('.npy'); a viscm source file ('.jscm'); or any text file. If the file is not a JSCM-file, it must contain the normalized; 8-bit; or hexadecimal string RGB values that define the colormap. ### Example Importing a colormap named 'test' can be done by saving its normalized RGB values in a file called 'cm_test.txt' and executing ```pycon >>> import_cmaps('/path/to/dir/cm_test.txt') ``` The 'test' colormap is now available in CMasher and MPL using ```pycon >>> cmr.cm.test # CMasher >>> plt.get_cmap('cmr.test') # MPL ``` ``` -------------------------------- ### Combine colormaps using Colormap objects Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Create a composite colormap by passing a list of existing matplotlib Colormap objects. ```pycon >>> cmap_0 = plt.get_cmap("Blues") >>> cmap_1 = plt.get_cmap("Oranges") >>> cmap_2 = plt.get_cmap("Greens") >>> custom_cmap_2 = combine_cmaps([cmap_0, cmap_1, cmap_2]) ``` -------------------------------- ### Plot with the rainforest colormap in R Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst Creates a test plot using the rainforest colormap from the loaded RDS object. Uses the built-in volcano dataset. ```R # Example use (volcano is an example dataset pre-loaded in every R installation): par(mar=c(4, 4, 1, 0.5)) layout(matrix(c(1, 2), 1, 2, byrow = TRUE), widths=c(3, 1)) image(volcano, col=cmr_cmaps$rainforest, main="rainforest") par(mar=c(5, 1, 5, 2.5)) image(y=seq(from=min(volcano), to=max(volcano), z=t(1:length(cmr_cmaps$rainforest)), by=(diff(range(volcano)))/length(cmr_cmaps$rainforest)), col=cmr_cmaps$rainforest, axes=FALSE, main="variable name", cex.main=0.8) axis(4, cex.axis=0.8, mgp=c(0, 0.5, 0)) ``` -------------------------------- ### get_bibtex() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Retrieves BibTeX entries for colormaps. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## get_bibtex() ### Description Retrieves BibTeX entries for colormaps. ### Method Function call ### Endpoint cmasher.get_bibtex ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### cmasher.take_cmap_colors Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Takes N equally spaced colors from the provided colormap cmap and returns them. Supports multiple return formats including normalized RGB tuples, 8-bit RGB tuples, and hexadecimal strings. ```APIDOC ## Function: cmasher.take_cmap_colors ### Description Takes N equally spaced colors from the provided colormap cmap and returns them. The colors can be returned in different formats: normalized RGB tuples, 8-bit RGB tuples, or hexadecimal strings. ### Signature cmasher.take_cmap_colors(cmap: Colormap | Name, N: int | None, cmap_range: tuple[float, float] = (0, 1), return_fmt: Literal['float', 'norm', 'int', '8bit', 'str', 'hex'] = 'float') ### Parameters #### Positional Parameters - **cmap** (str or Colormap object) - Required - The registered name of the colormap in matplotlib.cm or its corresponding Colormap object. - **N** (int or None) - Required - The number of colors to take from the provided cmap within the given cmap_range. If None, take all colors in cmap within this range. #### Other Parameters - **cmap_range** (tuple of float, default: (0, 1)) - Optional - The normalized value range in the colormap from which colors should be taken. By default, colors are taken from the entire colormap. - **return_fmt** ({'float'/'norm'; 'int'/'8bit'; 'str'/'hex'}, default: 'float') - Optional - The format of the requested colors. If 'float'/'norm', the colors are returned as normalized RGB tuples. If 'int'/'8bit', the colors are returned as 8-bit RGB tuples. If 'str'/'hex', the colors are returned using their hexadecimal string representations. ### Returns - **colors** (list of {tuple; str}) - The colors that were taken from the provided cmap. ### Examples Taking five equally spaced colors from the 'rainforest' colormap: ```default >>> take_cmap_colors('cmr.rainforest', 5) [(0.0, 0.0, 0.0), (0.226123592, 0.124584033, 0.562997277), (0.0548210513, 0.515835251, 0.45667819), (0.709615979, 0.722863985, 0.0834727592), (1.0, 1.0, 1.0)] ``` Requesting their 8-bit RGB values instead: ```default >>> take_cmap_colors('cmr.rainforest', 5, return_fmt='int') [(0, 0, 0), (58, 32, 144), (14, 132, 116), (181, 184, 21), (255, 255, 255)] ``` Requesting HEX-code values instead: ```default >>> take_cmap_colors('cmr.rainforest', 5, return_fmt='hex') ['#000000', '#3A2090', '#0E8474', '#B5B815', '#FFFFFF'] ``` Requesting colors in a specific range: ```default >>> take_cmap_colors('cmr.rainforest', 5, cmap_range=(0.2, 0.8), return_fmt='hex') ['#3E0374', '#10528A', '#0E8474', '#5CAD3C', '#D6BF4A'] ``` ### Notes Using this function on a perceptually uniform sequential colormap, like those in CMasher, allows one to pick a number of line colors that are different but still sequential. This is useful when plotting a set of lines that describe the same property, but have a different initial state. ``` -------------------------------- ### cmasher.take_cmap_colors(cmap: Colormap | Name, N: int | None, cmap_range: tuple[float, float] = (0, 1), return_fmt: Literal['float', 'norm'] = 'float') -> RGB[float] Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Extracts colors from a colormap. The function takes a colormap and returns a list of RGB colors. The number of colors and the range of the colormap to sample can be specified. ```APIDOC ## cmasher.take_cmap_colors(cmap: Colormap | Name, N: int | None, cmap_range: tuple[float, float] = (0, 1), return_fmt: Literal['float', 'norm'] = 'float') -> RGB[float] ### Description Extracts colors from a colormap. The function takes a colormap and returns a list of RGB colors. The number of colors and the range of the colormap to sample can be specified. ### Parameters - **cmap** (str or Colormap object) - Required - The registered name of the colormap in matplotlib.cm or its corresponding Colormap object. - **N** (int or None) - Required - The number of colors to extract. If None, the behavior is determined by the implementation. - **cmap_range** (tuple of float, default: (0, 1)) - Optional - The normalized range of the colormap to sample. - **return_fmt** (Literal['float', 'norm'], default: 'float') - Optional - The format of the returned colors. 'float' returns normalized RGB values, 'norm' returns normalized values in a different format. ### Returns - **RGB[float]** - A list of RGB colors. ``` -------------------------------- ### Take five colors in 8-bit RGB format Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Extracts five equally spaced colors from the 'cmr.rainforest' colormap as 8-bit RGB tuples. ```python >>> take_cmap_colors('cmr.rainforest', 5, return_fmt='int') [(0, 0, 0), (58, 32, 144), (14, 132, 116), (181, 184, 21), (255, 255, 255)] ``` -------------------------------- ### Take five colors in HEX format Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Extracts five equally spaced colors from the 'cmr.rainforest' colormap as hexadecimal strings. ```python >>> take_cmap_colors('cmr.rainforest', 5, return_fmt='hex') ['#000000', '#3A2090', '#0E8474', '#B5B815', '#FFFFFF'] ``` -------------------------------- ### Update the CMasher repository Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/lang_usage/R.rst If the repository is already cloned, navigate into it and pull the latest changes. ```default $ cd CMasher $ git pull ``` -------------------------------- ### cmasher.app_usage.update_tableau_pref_file Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.app_usage.rst Updates an existing Tableau 'Preferences.tps' file to include colormaps from CMasher, or creates the file if it does not exist. This function handles cases where colormaps have been modified or renamed in CMasher. ```APIDOC ## cmasher.app_usage.update_tableau_pref_file ### Description Updates an existing Tableau 'Preferences.tps' file to include colormaps from CMasher. The file is created if it does not exist yet. This function also accounts for colormaps that have been modified or renamed in CMasher. ### Method Function call ### Signature `update_tableau_pref_file(dirname: str | PathLike[str] = '.') -> None` ### Parameters #### Other Parameters - **dirname** (str or os.PathLike[str], Default: '.') - The relative or absolute path to the directory where the Tableau preferences file should be updated. If dirname contains an existing file called 'Preferences.tps', it will be updated to include CMasher colormap data. Otherwise, this file will be created in dirname. ### Returns None ### Notes In CMasher, colormaps sometimes get modified or renamed. This function takes these cases into account as well. ``` -------------------------------- ### Access CMasher colormaps in Python Source: https://github.com/1313e/cmasher/blob/master/docs/source/user/introduction.rst Import CMasher to register colormaps, then access them via the cmasher module or matplotlib's cm module using the 'cmr.' prefix. ```python # Import CMasher to register colormaps import cmasher as cmr # Import packages for plotting import matplotlib.pyplot as plt import numpy as np # Access rainforest colormap through CMasher or MPL cmap = cmr.rainforest # CMasher cmap = plt.get_cmap('cmr.rainforest') # MPL # Generate some data to plot x = np.random.rand(100) y = np.random.rand(100) z = x**2+y**2 # Make scatter plot of data with colormap plt.scatter(x, y, c=z, cmap=cmap, s=300) plt.show() ``` -------------------------------- ### view_cmap() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Displays a colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## view_cmap() ### Description Displays a colormap. ### Method Function call ### Endpoint cmasher.view_cmap ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### Generate scatter plot with CMasher colormap Source: https://github.com/1313e/cmasher/blob/master/README.rst Creates random data and plots a scatter plot using a colormap. The variable 'cmap' is assumed to be defined elsewhere, likely from CMasher. ```python # Generate some data to plot x = np.random.rand(100) y = np.random.rand(100) z = x**2+y**2 # Make scatter plot of data with colormap plt.scatter(x, y, c=z, cmap=cmap, s=300) plt.show() ``` -------------------------------- ### import_cmaps() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Imports colormaps from external sources. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## import_cmaps() ### Description Imports colormaps from external sources. ### Method Function call ### Endpoint cmasher.import_cmaps ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### Access rainforest colormap with CMasher Source: https://github.com/1313e/cmasher/blob/master/README.rst Imports CMasher to register colormaps in matplotlib and accesses the 'rainforest' colormap either directly from the cmasher module or via matplotlib's colormap registry with the 'cmr.' prefix. ```python # Import CMasher to register colormaps import cmasher as cmr # Import packages for plotting import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np # Access rainforest colormap through CMasher or MPL cmap = cmr.rainforest # CMasher cmap = mpl.colormaps['cmr.rainforest'] # MPL ``` -------------------------------- ### Take five colors from rainforest colormap Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Extracts five equally spaced colors from the 'cmr.rainforest' colormap in normalized RGB format. ```python >>> take_cmap_colors('cmr.rainforest', 5) [(0.0, 0.0, 0.0), (0.226123592, 0.124584033, 0.562997277), (0.0548210513, 0.515835251, 0.45667819), (0.709615979, 0.722863985, 0.0834727592), (1.0, 1.0, 1.0)] ``` -------------------------------- ### get_cmap_list() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Returns a list of available colormaps. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## get_cmap_list() ### Description Returns a list of available colormaps. ### Method Function call ### Endpoint cmasher.get_cmap_list ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### register_cmap() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Registers a colormap with matplotlib. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## register_cmap() ### Description Registers a colormap with matplotlib. ### Method Function call ### Endpoint cmasher.register_cmap ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### create_cmap_mod() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Creates a modified colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## create_cmap_mod() ### Description Creates a modified colormap. ### Method Function call ### Endpoint cmasher.create_cmap_mod ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### combine_cmaps() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Combines multiple colormaps into a single colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## combine_cmaps() ### Description Combines multiple colormaps into a single colormap. ### Method Function call ### Endpoint cmasher.combine_cmaps ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### Take five colors within a specific range Source: https://github.com/1313e/cmasher/blob/master/docs/source/api/cmasher.rst Extracts five equally spaced colors from the 'cmr.rainforest' colormap within the normalized range of 0.2 to 0.8. ```python >>> take_cmap_colors('cmr.rainforest', 5, cmap_range=(0.2, 0.8), return_fmt='hex') ['#3E0374', '#10528A', '#0E8474', '#5CAD3C', '#D6BF4A'] ``` -------------------------------- ### take_cmap_colors() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Extracts colors from a colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## take_cmap_colors() ### Description Extracts colors from a colormap. ### Method Function call ### Endpoint cmasher.take_cmap_colors ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### set_cmap_legend_entry() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Sets a legend entry for a colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## set_cmap_legend_entry() ### Description Sets a legend entry for a colormap. ### Method Function call ### Endpoint cmasher.set_cmap_legend_entry ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### update_tableau_pref_file() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Updates the Tableau preference file. This function is part of the CMasher application usage API and can be called directly by users. ```APIDOC ## update_tableau_pref_file() ### Description Updates the Tableau preference file. ### Method Function call ### Endpoint cmasher.app_usage.update_tableau_pref_file ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### get_sub_cmap() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Extracts a sub-colormap from an existing colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## get_sub_cmap() ### Description Extracts a sub-colormap from an existing colormap. ### Method Function call ### Endpoint cmasher.get_sub_cmap ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ``` -------------------------------- ### get_cmap_type() Source: https://github.com/1313e/cmasher/blob/master/docs/source/index.rst Returns the type of a colormap. This function is part of the CMasher API and can be called directly by users. ```APIDOC ## get_cmap_type() ### Description Returns the type of a colormap. ### Method Function call ### Endpoint cmasher.get_cmap_type ### Parameters No parameters are documented in the source. ### Request Example No request example is provided in the source. ### Response No response details are provided in the source. ### Response Example No response example is provided in the source. ```