In this post we collect some information about using colormaps for plotting. In particular, we pay attention to human perception.
!pip install husl
Cyclic (phase) Data¶
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
import husl
x = np.linspace(-2, 2, 256)[:, None]
y = x.T
z = x + 1j*y
zs = [0.5, -0.5]
psi = (z-zs[0]) * (z-zs[1])
theta = np.angle(psi)
plt.contourf(theta)
plt.colorbar()
def rgb(theta):
c = np.asarray(theta)/np.pi/2.0 + 0.5
res = np.asarray([husl.huslp_to_rgb(_c*100, 100.0, 50.0)
for _c in c.ravel()])
return res.reshape((3,) + c.shape)
res = rgb(theta)
plt.imshow?
from matplotlib.colors import Colormap
class HUSLP(Colormap):
def __init__(self, N=256):
Colormap.__init__(self, name='huslp', N=N)
def __call__(self, X, alpha=None, bytes=False):
"""
Parameters
----------
X : scalar, ndarray
The data value(s) to convert to RGBA.
For floats, X should be in the interval ``[0.0, 1.0]`` to
return the RGBA values ``X*100`` percent along the Colormap line.
For integers, X should be in the interval ``[0, Colormap.N)`` to
return RGBA values *indexed* from the Colormap with index ``X``.
alpha : float, None
Alpha must be a scalar between 0 and 1, or None.
bytes : bool
If False (default), the returned RGBA values will be floats in the
interval ``[0, 1]`` otherwise they will be uint8s in the interval
``[0, 255]``.
Returns
-------
Tuple of RGBA values if X is scalar, othewise an array of
RGBA values with a shape of ``X.shape + (4, )``.
"""