user308827
user308827

Reputation: 22041

Set first element of colormap in matplotlib to gray

How can I change the first color in a listed colormap in matplotlib to gray? I created the colormap as follows:

import matplotlib.pyplot as plt
plt.get_cmap('viridis_r')

Upvotes: 0

Views: 268

Answers (1)

mitoRibo
mitoRibo

Reputation: 4548

Sorry I haven't tested this, but does this work?

>>> col_map = plt.get_cmap('viridis_r')
>>> col_map.__dict__['colors'].insert(0,[0.5,0.5,0.5])

Upvotes: 1

Related Questions