Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

kcrisman is absolutly rigth:

here are some code examples based on that articel Custom Colormaps

With a lookup dict:

from pylab import *
cdict = {'red': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.7),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 1.0, 1.0)),
'blue': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 0.5, 1.0))}
my_cmap = matplotlib.colors.LinearSegmentedColormap( 'my_colormap', cdict, 256 )
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = my_cmap, colorbar = True )
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = my_cmap, colorbar = True )

From pool:

from pylab import *
N=8
cpool = [ '#bd2309', '#bbb12d', '#1480fa', '#14fa2f', '#000000',
'#faf214', '#2edfea', '#ea2ec4', '#ea2e40', '#cdcdcd',
'#577a4d', '#2e46c0', '#f59422', '#219774', '#8086d9' ]
cmap3 = matplotlib.colors.ListedColormap(cpool[0:N], 'indexed')
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = cmap3, colorbar = True )

As gradient:

from pylab import *
startcolor = '#FF0000'
midcolor = '#FFFFFF'
endcolor = '#0030CC'
own_cmap1 = matplotlib.colors.LinearSegmentedColormap.from_list( 'own2', [startcolor, midcolor, endcolor] )
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = own_cmap1, colorbar = True )

kcrisman @kcrisman is absolutly rigth:right:

here are some code examples based on that articel Custom Colormaps

With a lookup dict:

 from pylab import * 
* cdict = {'red': ((0.0, 0.0, 0.0),
0.0), (0.5, 1.0, 0.7),
0.7), (1.0, 1.0, 1.0)),
1.0)), 'green': ((0.0, 0.0, 0.0),
0.0), (0.5, 1.0, 0.0),
0.0), (1.0, 1.0, 1.0)),
1.0)), 'blue': ((0.0, 0.0, 0.0),
0.0), (0.5, 1.0, 0.0),
0.0), (1.0, 0.5, 1.0))}
1.0))} my_cmap = matplotlib.colors.LinearSegmentedColormap( 'my_colormap', cdict, 256 )
) matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = my_cmap, colorbar = True )
)

From pool:

from pylab import *
N = 8
cpool = [ '#bd2309', '#bbb12d', '#1480fa', '#14fa2f', '#000000',
          '#faf214', '#2edfea', '#ea2ec4', '#ea2e40', '#cdcdcd',
          '#577a4d', '#2e46c0', '#f59422', '#219774', '#8086d9' ]
cmap3 = matplotlib.colors.ListedColormap(cpool[0:N], 'indexed')
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = my_cmap, cmap3, colorbar = True )
)

From pool:

As gradient:

 from pylab import * 
N=8
cpool = [ '#bd2309', '#bbb12d', '#1480fa', '#14fa2f', '#000000',
'#faf214', '#2edfea', '#ea2ec4', '#ea2e40', '#cdcdcd',
'#577a4d', '#2e46c0', '#f59422', '#219774', '#8086d9' ]
cmap3 = matplotlib.colors.ListedColormap(cpool[0:N], 'indexed')
* startcolor = '#FF0000' midcolor = '#FFFFFF' endcolor = '#0030CC' own_cmap1 = matplotlib.colors.LinearSegmentedColormap.from_list( 'own2', [startcolor, midcolor, endcolor] ) matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = cmap3, colorbar = True )

As gradient:

from pylab import *
startcolor = '#FF0000'
midcolor = '#FFFFFF'
endcolor = '#0030CC'
own_cmap1 = matplotlib.colors.LinearSegmentedColormap.from_list( 'own2', [startcolor, midcolor, endcolor] )
matrix_plot( matrix( [ [1,3,5,1], [2,4,5,6], [1,-3,5,7] ] ), cmap = own_cmap1, colorbar = True )
)