Ask Your Question
0

Custom color map for matrix plot?

asked 2014-09-08 17:27:10 +0100

balduin gravatar image

updated 2014-09-08 19:21:00 +0100

I need colormap which has for a fixed value x the color white and all values above x are colorized from white do blue and all values below x are colorized from white to red.

The first question is, is this possible? And my second question how can I do that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-09-08 17:50:39 +0100

kcrisman gravatar image

You'll probably have to make a custom colormap and then pass that right in to matrix_plot, perhaps using ListedColormap or LinearSegmentedColormap. But I think this should be doable, as we use matplotlib colormaps as they stand.

edit flag offensive delete link more

Comments

I try this thanks

balduin gravatar imagebalduin ( 2014-09-08 19:12:30 +0100 )edit
2

answered 2014-09-18 15:02:04 +0100

balduin gravatar image

updated 2014-09-19 16:59:30 +0100

slelievre gravatar image

@kcrisman is absolutly 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.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 )

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 )
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-09-08 17:27:10 +0100

Seen: 1,139 times

Last updated: Sep 19 '14