Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: Custom colormap with three colors [duplicate]

I would like to pass a colormap to a matplotlib.imshow to plot a NxN array where each cell can only take the values -1,0 and 1. I would like my colormap to map exactly one color (in hex code) to each value.

I just have no idea how to define a custom colormap which is not a gradation between two colors.

like image 882
Learning is a mess Avatar asked Oct 05 '15 16:10

Learning is a mess


1 Answers

A solution to a very similar question was provided here. In summary ,

import matplotlib
matplotlib.colors.ListedColormap(list-of-colours)

is your friend.

like image 57
fernando Avatar answered Oct 02 '22 19:10

fernando