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.
# Copy this into your browser to see the map at colorbrewer2.org.
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

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)

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.2.zip (19.5 kB view details)

Uploaded Source

brewer2mpl-1.2.tar.gz (17.5 kB view details)

Uploaded Source

File details

Details for the file brewer2mpl-1.2.zip.

File metadata

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

File hashes

Hashes for brewer2mpl-1.2.zip
Algorithm Hash digest
SHA256 7cdcea4bfa2ca1dfa86f074e0ef21a8177ab8bd2a5b6a2aa56d6aef986191bb9
MD5 bd7edf3f1f7f5641ef5a6f561eb9a928
BLAKE2b-256 1b24a520b1d5e67e79d4ee47ac3d18b3c5ecb9e3b9d81f776337bba9b56d2ed2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for brewer2mpl-1.2.tar.gz
Algorithm Hash digest
SHA256 b0f63f8782c57fc824be870b227973c282cf0b0961b00ecefbea1fe104138014
MD5 a7c17e6413cfc46b5a7b4fc6020f60c4
BLAKE2b-256 435a0a0a29d399cc150562b02f73bceb495b94fa050cd164c79bb5d33fb00274

See more details on using hashes here.

Supported by

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