0

Following on from all my other annoying hard to understand posts I have a list:

[0,1,4,3,2,4,2,1,0]

I want each of them to have a colour using

cmap = mpl.colors.ListedColormap([[1,0,0],[0,0,1],[0,1,0],[1,1,0],[0,1,1]])

will get me colors red, blue green yellow and light blue.

What I want is the colours to start from red and end in blue and the others to be in between those colours.

I'd probably be able to do it in the same sort of way, but I'm guessing there would be better way then this using some sort of equation?

mgilson
  • 300,191
  • 65
  • 633
  • 696
John Smith
  • 1,089
  • 3
  • 18
  • 37
  • 1
    Do these help at all? http://matplotlib.org/examples/pylab_examples/show_colormaps.html – mgilson Feb 20 '13 at 13:24
  • You need to use a LinearSegmentedColormap instead of a ListedColorMap. – Rutger Kassies Feb 20 '13 at 14:27
  • You can see examples of the use of LinearSegmentedColormap here: http://stackoverflow.com/questions/9893440/python-matplotlib-colormap or http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps. Docs: http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap – joris Feb 20 '13 at 18:54

1 Answers1

0

You can fake it. Say you want to the first third of the line in red, the next in blue and the next in green.

You need to create 3 separate lines in your data. You need three lines that look like:

[0,1,4,None,None,None,None,None,None]
[None,None,None,3,2,4,None,None,None]
[None,None,None,None,None,None,2,1,0]

The lines are padded with Nones to make it look like matplotlib is plotting in a continuous line. Then you plot each of the lines and tell matplotlib what colour you want

jhulme
  • 100
  • 10