matplotlib:将colormap转换为柔和颜色

发布于 2025-01-29 20:23:03 字数 371 浏览 5 评论 0原文

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2025-02-05 20:23:03

经过一项研究,我采用了画家使用的解决方案来获取柔和的颜色:将颜色与白色油漆混合。用Pythonic术语,如果我想选择,例如n蓝色阴影,我将

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()

c控制“柔软/柔和”的程度。因此,对于c = 0纯色是

对于c = 0.2

对于c = 0.4

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文