You're not defining your dictionary in the way specified in the link. In fact, 
I don't think you have a dictionary at all.

"First, create a script that will map the range (0,1) to values in the RGB 
spectrum. In this dictionary, you will have a series of tuples for each color 
'red', 'green', and 'blue'. The first elements in each of these color series 
needs to be ordered from 0 to 1, with arbitrary spacing in between. Now, 
consider (0.5, 1.0, 0.7) in the 'red' series below. This tuple says that at 0.5 
in the range from (0,1) , interpolate from below to 1.0, and above from 0.7. 
Often, the second two values in each tuple will be the same, but using 
different values is helpful for putting breaks in your colormap. This is easier 
understand than might sound, as demonstrated by this simple script"

From: Jim Vickroy [mailto:jim.vick...@noaa.gov]
Sent: Wednesday, June 16, 2010 9:15 AM
To: Paul Hobson
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] how to define custom colormap from set of RGB 
values ?

phob...@geosyntec.com<mailto:phob...@geosyntec.com> wrote:
Give this a shot:
http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps

Thanks for your reply.

Previously, I had tried something based on the second example at that URL, but, 
after considerable time, I could only get a palette that was "close".  I do not 
understand how to use that example to replicate an IDL color map.

The requirement is for me to exactly duplicate the IDL color map (actually 
several IDL color maps) listed in my script.

-- jv


From: Jim Vickroy [mailto:jim.vick...@noaa.gov]
Sent: Wednesday, June 16, 2010 8:14 AM
To: Matplotlib
Subject: [Matplotlib-users] how to define custom colormap from set of RGB 
values ?

Hello,

The attached script shows my (failed) attempt to define a custom color map from 
a set of RGB values (taken from an IDL palette).

My approach is presumably completely wrong, but I have not found information or 
examples on how to do this.

Could someone point in the right direction?

Thanks,

-- jv

P.S.
When run on my workstation, the output from the attached script is:

<output>
Python version:     2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 
bit (Intel)]
matplotlib version: 0.99.3
numpy version:      1.4.0
Traceback (most recent call last):
  File "custom-colormap.py", line 97, in <module>
    plotter.savefig('%s.png' %colormap.name, facecolor='black', 
edgecolor='black')
  File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 356, in 
savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1032, in 
savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 1476, 
in print_figure
    **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 
358, in print_png
    FigureCanvasAgg.draw(self)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 
314, in draw
    self.figure.draw(self.renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 46, in 
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 773, in draw
    for a in self.axes: a.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 46, in 
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 1701, in draw
    im.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 46, in 
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\image.py", line 237, in draw
    im = self.make_image(renderer.get_image_magnification())
  File "C:\Python26\lib\site-packages\matplotlib\image.py", line 182, in 
make_image
    x = self.to_rgba(self._A, self._alpha)
  File "C:\Python26\lib\site-packages\matplotlib\cm.py", line 167, in to_rgba
    x = self.cmap(x, alpha=alpha, bytes=bytes)
  File "C:\Python26\lib\site-packages\matplotlib\colors.py", line 489, in 
__call__
    if not self._isinit: self._init()
  File "C:\Python26\lib\site-packages\matplotlib\colors.py", line 720, in _init
    for c in self.colors], np.float)
  File "C:\Python26\lib\site-packages\matplotlib\colors.py", line 311, in to_rgb
    raise ValueError('to_rgb: Invalid rgb arg "%s"\n%s' % (str(arg), exc))
ValueError: to_rgb: Invalid rgb arg "(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 
4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 25, 26, 
28, 29, 31, 33, 34, 36, 38,
40, 41, 43, 45, 47, 49, 50, 53, 55, 57, 59, 61, 64, 66, 68, 70, 72, 74, 76, 79, 
82, 84, 87, 89, 91, 94, 96, 99, 101, 104, 106, 108, 110, 113, 116, 118, 121, 
124, 127, 128, 131, 134, 137
, 138, 141, 144, 147, 149, 152, 155, 156, 160, 161, 164, 168, 169, 172, 174, 
177, 179, 182, 184, 188, 189, 191, 195, 196, 198, 202, 203, 205, 209, 211, 212, 
214, 216, 220, 222, 224, 225
, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 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, 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, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 
255, 255, 255, 255, 255, 255, 255, 255)"
sequence length is 256; must be 3 or 4
</output>

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to