Did you check values in palette?

With

 palette /= 255

you're setting the value in place. Because the palette.dtype is int,
the result is also an integer array, i.e., only with with zeros and
ones.

You may do

 palette = [reds,greens,blues]
 palette = numpy.array(palette, dtype="d")

Regards,

-JJ




On Wed, Jun 16, 2010 at 1:40 PM, Jim Vickroy <jim.vick...@noaa.gov> wrote:
> Jae-Joon Lee wrote:
>>
>> As you can see from the error, the dimension of your input is wrong
>> (it needs to be transposed).
>> Furthermore, matplotlib expects the rgb values in 0-1.
>>
>> replace
>>
>>  colormap = matplotlib.colors.ListedColormap(palette,'custom-orange')
>>
>> with
>>
>>  colormap =
>> matplotlib.colors.ListedColormap(palette.T/255.,'custom-orange')
>>
>> Regards,
>>
>> -JJ
>>
>
> Thanks much for this  JJ !
>
> I have a follow-up question. :-(
>
> The attached script is a slight modification of the one originally posted.
>
> The attached PNG files are the outputs from the attached script.
>
> Prior to my original post, I had actually tried something "similar" to your
> solution -- namely:
>
> palette = [reds,greens,blues]
> palette = palette.transpose()
> palette /= 255.0
> colormap = matplotlib.colors.ListedColormap(palette,'custom-orange-jv')
>
> I do not know why the 2 PNG files are so different in appearance (and size).
>
> I would appreciate some help understanding this.
>
> Thanks,
> -- jv
>
> P.S.
> As seen in the attached script, the orange-JJ.png is the result of using
> your (i.e., JJ's) solution.
>
>
>
>>
>> On Wed, Jun 16, 2010 at 11:13 AM, Jim Vickroy <jim.vick...@noaa.gov>
>> wrote:
>>
>>>
>>> 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
>>>
>>>
>>>
>
>

------------------------------------------------------------------------------
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