rek*_*xip 3 python matplotlib scatter-plot imshow colormap
我正在尝试为簇制作背景颜色,但不知道如何使喷射颜色图更亮或更暗。有人可以帮助我吗?
这肯定取决于您如何定义“较亮”或“较暗”。一个有用的定义是乘以 HSL 空间中颜色的亮度通道。这可能看起来像
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import colorsys
def man_cmap(cmap, value=1.):
colors = cmap(np.arange(cmap.N))
hls = np.array([colorsys.rgb_to_hls(*c) for c in colors[:,:3]])
hls[:,1] *= value
rgb = np.clip(np.array([colorsys.hls_to_rgb(*c) for c in hls]), 0,1)
return mcolors.LinearSegmentedColormap.from_list("", rgb)
cmap = plt.cm.get_cmap("jet")
fig, (ax1, ax2, ax3) = plt.subplots(3)
x=np.linspace(0,1,64)
sc = ax1.scatter(x,np.ones_like(x), c=x, cmap=cmap)
fig.colorbar(sc, ax=ax1, orientation="horizontal")
sc = ax2.scatter(x,np.ones_like(x), c=x, cmap=man_cmap(cmap, 0.75))
fig.colorbar(sc, ax=ax2, orientation="horizontal")
sc = ax3.scatter(x,np.ones_like(x), c=x, cmap=man_cmap(cmap, 1.25))
fig.colorbar(sc, ax=ax3, orientation="horizontal")
plt.show()
Run Code Online (Sandbox Code Playgroud)