Matplotlib: convert colormap to pastel colors

Question:

I am currently using color shades from single color matplotlib colormaps (like Blues, Purples, Greens). However I would prefer softer, "pastel" tones. How could I soften the existing colormaps or perhaps there are more appropriate colormaps to use for this purpose?

Remark: my question is essentially a python version of this one: R convert colors to pastel colors.

Asked By: Roger Vadim

||

Answers:

After some research I have adopted the solution used by painters to obtain pastel colors: mixing the color with white paint. In pythonic terms, if I want to chose, e.g., n shades of blue, I take

n = 15
colors = (1. - c) * plt.get_cmap("Blues_r")(np.linspace(0., 1., n)) + c * np.ones((n, 4))
plt.scatter(np.arange(n),np.ones(n), c=colors, s=180)
plt.show()

where c controls the degree of "softness/pastelness". Thus, for c=0 the pure color is
enter image description here

for c=0.2
enter image description here

for c=0.4
enter image description here

Answered By: Roger Vadim