Reputation: 61
I tried this:
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
cmap = colors.ListedColormap(['#e3eeee', '#3c0736'])
But when I plot it, I got this (see the legend): I want to have the first color, as set in the list, but not a repeated 2 colors.
Upvotes: 0
Views: 229
Reputation: 562
I am not sure I understood your problem correctly, but maybe this can help you.
If you want to have once the first color and then repeat the second, you could try to repeat it (more of an hack):
cmap = colors.ListedColormap(['#e3eeee'] + ['#3c0736']*n)
where n
is the number of times second color should repeat;
If instead your are looking to have a custom scale between two colors you could try:
cmap = colors.LinearSegmentedColormap.from_list("Custom", ['#e3eeee'] + ['#3c0736'], N=n)
where n
is the number of discrete cases in which you divided your population (7 in your case).
Upvotes: 1