Matlab colormap to matplotlib

Hello list,

I know that this is very simple for most of the people, but since it took some time to figure it out I'm sharing here. It's useful for those that, like me, have dozens of personalized colormaps in matlab r,g,b lists.

def cmat2cmpl(r, g, b):
     """
     Convert matlab style colormap to matplotlib style
     Enter a list non normalized RGB values from 0-255
     """
     r = np.array(r)/255.
     g = np.array(g)/255.
     b = np.array(b)/255.

     cmap = mpl.colors.ListedColormap(zip(r,g,b))
     return cmap

r = [8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 10, 9, 8, 8, 7, 6, 5, 5, 4, 3, 2, 2, 1, 0, 0]
g = [241, 237, 234, 231, 228, 225, 222, 218, 215, 212, 209, 204, 199, 194, 190, 185, 180, 175, 171, 166, 161, 160, 158, 157, 156, 154, 153, 152, 150, 149, 148, 146, 145, 144, 142, 141, 140, 134, 129, 124, 119, 114, 109, 103, 98, 93, 88, 83, 77, 72, 67, 62, 57, 51, 46, 41, 36, 31, 25, 20, 15, 10, 5, 0]
b = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 247, 240, 232, 225, 217, 210, 202, 195, 188, 180, 173, 165, 158, 150, 143]

mycmap = cmat2cmpl(r, g, b)
a=outer(arange(0,1,0.001),ones(10))
imshow(a,aspect='auto',cmap=mycmap,origin="lower")