Colors#

This library uses the Accessible Color Sequences for Data Visualization by Matthew A. Petroff.

Hide code cell content

%load_ext autoreload
%autoreload 2

import matplotlib.pyplot as plt
import numpy as np
import xplt

xplt.apply_style()

Color palette#

xplt.cmap_petroff
petroff
petroff colormap
under
bad
over

Color gradients#

xplt.cmap_petroff_gradient
petroff_gradient
petroff_gradient colormap
under
bad
over

xplt.cmap_petroff_bipolar
petroff_bipolar
petroff_bipolar colormap
under
bad
over

xplt.cmap_petroff_cyclic
petroff_cyclic
petroff_cyclic colormap
under
bad
over

Usage#

With xplt.apply_style() in the import section above, the default color cycle is updated to use the petroff colors.
The colors are also accessible by name as p0, p1, … p9 even without applying Xplt’s style:

plt.figure(figsize=(5, 1))
plt.plot(np.linspace(5, 0) % 2)
plt.plot(np.linspace(0, 5) % 2, color="p2");
../_images/61c64679b47d2ce627c0f6f86efda6d5a8562ae7fcd0da659c4533160298e7e2.png

Colormaps can be used like cmap='petroff_bipolar':

fig, ax = plt.subplots()
t = np.linspace(0, 2 * np.pi, 1024)
data2d = np.sin(t)[:, np.newaxis] * np.cos(t)[np.newaxis, :]
im = ax.imshow(data2d, cmap="petroff_bipolar")
fig.colorbar(im, ax=ax, label="Color");
../_images/6f8b76c16ebc0cca5616cc5907bf648da583602f4f534913c323020a6208ff66.png

See also