Skip to main content

Connect colorbrewer2.org color maps to Python and matplotlib

Project description

brewer2mpl is a pure Python package for accessing colorbrewer2.org color maps from Python. With brewer2mpl you can get the raw RGB colors of all 165 colorbrewer2.org color maps. The color map data ships with brewer2mpl so no internet connection is required.

For more information and to view some of the color maps see the wiki at https://github.com/jiffyclub/brewer2mpl/wiki.

Color Maps

colorbrewer2.org has 3 map types: sequential, diverging, and qualitative. Each color map has between 3 and 12 defined colors.

Examples

Listing Color Maps

List all of the available color maps:

brewer2mpl.print_maps()

List maps by type:

brewer2mpl.print_maps('sequential')

Filter by number of colors defined:

brewer2mpl.print_maps('qualitative', 6)

Get a Color Map

Color maps are accessed by name, type, and number:

bmap = brewer2mpl.get_map('Paired', 'Qualitative', 5)

If you want a color map reversed from how it is given by colorbrewer2.org set the reverse keyword to True:

bmap = brewer2mpl.get_map('Paired', 'Qualitative', 5, reverse=True)

BrewerMap Objects

Color maps are represented by BrewerMap objects. They have a few useful attributes:

# colorbrewer2.org url.
bmap.colorbrewer2_url

# colorbrewer2.org name
bmap.name

# number of defined colors
bmap.number

# colors as a list of RGB 0-255 triplets
bmap.colors

# colors as a list of hex strings
bmap.hex_colors

# colors as a list of RGB 0-1 triplets (as used by matplotlib)
bmap.mpl_colors

# matplotlib color map
bmap.mpl_colormap

To launch your browser and see a color map at colorbrewer2.org use the colorbrewer2 method:

bmap.colorbrewer2()

The matplotlib color maps are created using matplotlib.colors.LinearSegmentedColormap.from_list. If you want to pass options to that method use the BrewerMap.get_mpl_colormap method:

cmap = bmap.get_mpl_colormap(N=1000, gamma=2.0)

Direct Access

If you know the color map you want there is a shortcut for direct access. You can import the sequential, diverging, or qualitative modules from brewer2mpl. On the module namespace are dictionaries containing BrewerMap objects keyed by number of defined colors.

Say you want the Dark2 qualitative color map with 7 colors. To get it directly you can do:

from brewer2mpl import qualitative
bmap = qualitative.Dark2[7]

There is also a special key ‘max’ for each name that points to the color map with the most defined colors:

from brewer2mpl import sequential
bmap = sequential.YlGnBu['max']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

brewer2mpl-1.3.2.zip (20.1 kB view details)

Uploaded Source

brewer2mpl-1.3.2.tar.gz (17.4 kB view details)

Uploaded Source

File details

Details for the file brewer2mpl-1.3.2.zip.

File metadata

  • Download URL: brewer2mpl-1.3.2.zip
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for brewer2mpl-1.3.2.zip
Algorithm Hash digest
SHA256 298291cc3c6fd3110886c868007714bd54ba3032398fc71607156db3efdcbd14
MD5 0d17bdcfd4c27518447d60a085eb213f
BLAKE2b-256 fc847786c12576f88a505becc76fd0f702f457ca7c0fd849f411632db1bb3640

See more details on using hashes here.

File details

Details for the file brewer2mpl-1.3.2.tar.gz.

File metadata

  • Download URL: brewer2mpl-1.3.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for brewer2mpl-1.3.2.tar.gz
Algorithm Hash digest
SHA256 ff50b36ac60521f32d6b7d454e8d7f628e67be9f184ab79ba6b07fd328304b06
MD5 7d4df4329f3022c003fa1c045619e321
BLAKE2b-256 efeddf4446781cabf0d79e7da087d24ac4b694318d66951d98f379d5ef7f78f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page