Skip to content

Instantly share code, notes, and snippets.

@jgomezdans
Created May 15, 2010 23:24
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jgomezdans/402500 to your computer and use it in GitHub Desktop.
Save jgomezdans/402500 to your computer and use it in GitHub Desktop.
Random colormap for matplotli
import matplotlib,numpy
import pylab
# A random colormap for matplotlib
cmap = matplotlib.colors.ListedColormap ( numpy.random.rand ( 256,3))
pylab.imshow ( Z, cmap = cmap)
pylab.show()
@jgomezdans
Copy link
Author

This is a random colormap for matplotlib, quite useful for segmentation displays and stuff

@mprakhar
Copy link

mprakhar commented Sep 4, 2017

slick!

@jmetz
Copy link

jmetz commented Nov 21, 2017

Try the following if you want a randomly shuffled version of an existing colormap (might be useful to avoid potentially bad colors from using purely random RGB values):

import numpy as np
import matplotlib.pyplot as plt
vals = np.linspace(0,1,256)
np.random.shuffle(vals)
cmap = plt.cm.colors.ListedColormap(plt.cm.jet(vals))

replacing jet with the colormap of your choice.

@hyperfraise
Copy link

hello. If you have a way to perform the same operation in opencv, i'm really interested ! (cmap isn't a proper opencv colormap)

@edwardando
Copy link

edwardando commented Mar 29, 2018

Brilliant, even better than glasbey on ImageJ

@kheffah
Copy link

kheffah commented Jul 2, 2018

This is awesome, very helpful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment