It seems you are asking for a BoundaryNorm
.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
cmap = matplotlib.colors.ListedColormap(["limegreen", "gold", "crimson"])
norm = matplotlib.colors.BoundaryNorm([0,10,50,55], 3)
x = np.linspace(0,55)
fig, (ax, ax2) = plt.subplots(ncols=2)
sc = ax.scatter(x,x, c=x, cmap=cmap, norm=norm)
fig.colorbar(sc, ax=ax, spacing="uniform")
sc2 = ax2.scatter(x,x, c=x, cmap=cmap, norm=norm)
fig.colorbar(sc2, ax=ax2, spacing="proportional")
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…