Ich bin auf dieses Problem gestoßen, als ich versuchte, Daten mit verschiedenen Farbkarten darzustellen:
![Blues vs Reds]()
Es ist schwer zu erkennen, welche der weißlichen Punkte zu welcher Verteilung gehören. Ich habe dieses Problem gelöst, indem ich die weißeren Teile des Spektrums der Farbkarte abgeschnitten habe:
![Blues vs Reds with white removed]()
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
def chop_cmap_frac(cmap: LinearSegmentedColormap, frac: float) -> LinearSegmentedColormap:
"""Chops off the beginning `frac` fraction of a colormap."""
cmap_as_array = cmap(np.arange(256))
cmap_as_array = cmap_as_array[int(frac * len(cmap_as_array)):]
return LinearSegmentedColormap.from_list(cmap.name + f"_frac{frac}", cmap_as_array)
cmap1 = plt.get_cmap('Reds')
cmap2 = plt.get_cmap('Blues')
cmap1 = chop_cmap_frac(cmap1, 0.4)
cmap2 = chop_cmap_frac(cmap2, 0.4)
np.random.seed(42)
n = 50
xs = np.random.normal(size=n)
ys = np.random.normal(size=n)
vals = np.random.uniform(size=n)
plt.scatter(xs, ys, c=vals, cmap=cmap1)
plt.scatter(ys, xs, c=vals, cmap=cmap2)
plt.gca().set_facecolor('black')
plt.colorbar()
plt.show()