Skip to main content

Enums representing named colors available in matplotlib

Project description

mpl_colors

A python 3.6+ library extending matplotlib's color handling.

Named color enums

Makes matplotlib's named colors more discoverable.

Defines enums for each of matplotlib's sets of named colours (base, Tableau, xkcd and CSS4), and one which combines all of them (where Tableau and xkcd names are prepended with TAB_ and XKCD_ respectively, like matplotlib). Color names are in SCREAMING_SNAKE_CASE, as recommended. Names originally containing a slash (/) replace it with the _SLASH_ (necessary to prevent collisions).

Instances of these enums are also instances of a named tuple with members r, g, and b (all floats between 0 and 1). They also support a number of methods for conversion into colour.Color objects, and RGBA, HSL, HSV, and YIQ tuples. Also, length-6 hex strings (prepended with #) and colour's "web" format (whichever is shortest of W3C named color, length-3 hex, or length-6 hex, preferring named as a tie-break).

The enums are automatically generated directly from matplotlib.colors using the included make_colors.py. Like matplotlib, they support both spellings of the word "grey"/"gray".

LabelColormap

matplotlib.colors.Colormap subclass which deterministically converts integers into a random RGB tuple.

from matplotlib import pyplot as plt
import numpy as np

from mpl_colors import LabelColorMap

img = np.random.randint(0, 255, (20, 20), dtype=np.uint8)
masked = np.ma.masked_where(img < 100, img)

fig, ax = plt.subplots()
ax.imshow(masked, cmap=LabelColorMap(), interpolation='nearest')
fig.show()

Project details


Download files

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

Files for mpl-colors, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size mpl_colors-0.2.0-py3-none-any.whl (31.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size mpl_colors-0.2.0.tar.gz (31.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page