Overview of Palettable
masterbrewer2mpl) is a pure Python library providing a collection of color palettes. It has no external dependencies and is designed to be used for customizing matplotlib plots or providing color data for web applications.repository·master·Indexed 21 days ago
https://github.com/jiffyclub/palettableA Python library providing a wide collection of color palettes, including those from Colorbrewer, CartoColors, cmocean, and Light and Bartlein. It offers a consistent interface to access colors as RGB tuples, hex strings, or matplotlib colormaps, and includes tools for visualizing palettes as blocks or continuous images in IPython environments. The library also supports algorithmic generation of custom Cubehelix color maps.
brewer2mpl) is a pure Python library providing a collection of color palettes. It has no external dependencies and is designed to be used for customizing matplotlib plots or providing color data for web applications.Scientific palettes in palettable are based on the work of Fabio Crameri. These palettes are designed for scientific visualization and are available with up to 256 discreetly defined colors.
They are organized into three sub-modules based on their color distribution type:
palettable.scientific.diverging: For palettes that transition between two different colors, typically through a neutral midpoint.palettable.scientific.sequential: For palettes that represent data moving in one direction (e.g., low to high).palettable.scientific.qualitative: For palettes used to represent discrete, unordered categories.Palettes are pre-built and loaded at import time. They follow a naming convention of <Name>_<number of colors>. For example, the Colorbrewer2 palette Dark2 with seven colors is named Dark2_7.
Every palette also has a reversed version with the same name plus the suffix _r (e.g., Dark2_7_r).
Palettes are organized into modules based on their source (e.g., cartocolors, cmocean, colorbrewer, plotly, tableau) and their type (diverging, qualitative, or sequential).
from palettable.colorbrewer.qualitative import Dark2_7Palettable integrates deeply with matplotlib through several attributes:
To change the default color cycle used when drawing plots, use the .mpl_colors attribute with ax.set_prop_cycle().
ax.set_prop_cycle('color', palettable.colorbrewer.qualitative.Dark2_8.mpl_colors)For functions that accept a cmap argument (like imshow), use the .mpl_colormap attribute.
from palettable.colorbrewer.sequential import Blues_8
ax.imshow(data, cmap=Blues_8.mpl_colormap)Since .mpl_colormap is continuous/interpolated, use matplotlib.colors.ListedColormap with .mpl_colors to create a discrete version.
from matplotlib.colors import ListedColormap
cmap = ListedColormap(palettable.colorbrewer.qualitative.Dark2_7.mpl_colors)To include a new Palettable module in the documentation, follow these steps:
index.md.tpl file inside the new directory. This file must use Jinja templating to generate the table-of-contents and include palette preview images. You can use matplotlib/index.md.tpl as a reference.MODULES dictionary in the gendocs.py script to map your new module to its corresponding directory.make images, make compile, make build) to verify the changes.The cmocean palettes in Palettable are sourced from the original cmocean package. They are organized into two sub-modules based on their color application type:
palettable.cmocean.diverging: For diverging color schemes.palettable.cmocean.sequential: For sequential color schemes.Install the palettable library using pip. It is compatible with Python 2.6, 2.7, and Python 3.
pip install palettableLight and Bartlein palettes are sourced from the Department of Geography at the University of Oregon. They are organized into two distinct sub-modules based on their color scale type:
palettable.lightbartlein.diverging for scales that transition from one color to another through a neutral midpoint.palettable.lightbartlein.sequential for scales that represent ordered data through a single color progression.Colorbrewer palettes are available in palettable through three sub-modules, categorized by their intended use case:
palettable.colorbrewer.divergingpalettable.colorbrewer.qualitativepalettable.colorbrewer.sequentialCartoColors palettes are available in palettable and are categorized into three sub-modules based on their intended use case:
These palettes are derived from the CartoColors node module.
The Palettable documentation is generated using a combination of hand-curated content and Jinja templates (.md.tpl files). The gendocs.py script compiles these templates into Markdown, which is then converted to HTML by Urubu.
To build the documentation, you must have the following installed:
palettablematplotlibJinjaUrubutservicemake images to generate palette preview images.make compile to compile the .md.tpl files into Markdown (if images are already up-to-date)._site.yml.make build to trigger the Urubu build process.make serve to preview the documentation locally.make images
make compile
make build
make serveYou can reverse the order of any pre-made Cubehelix color map by appending _r to its name (e.g., cubehelix.cubehelix3_16_r).
cubehelix.cubehelix3_16_r.show_continuous_image()