SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: James B. <bo...@ll...> - 2006年06月29日 16:54:11
Attachments: pastedGraphic1.tiff
I am interested in producing a color map and accompanying colorbar with 
non-linear (arbitrary) spacing. My intent is like the attached color 
bar in which the increments are monotonic but vary in size. There might 
be an easy way to do this but it is not apparent to me.
--Jim
From: David H. <dav...@gm...> - 2006年06月29日 19:09:49
Hi Jim,
I guess you'd have to write a custom palette dictionnary do to that. If you
already have a GMT file, check the link
www.scipy.org/Cookbook/Matplotlib/Loading_a_colormap_dynamically
You could also take a cpt file you like, see for example
http://pdfb.wiredworkplace.net/cpt-city/www/cb/seq/index.html
tweak it to fit your needs and use the script below to convert it to a
format matplotlib will understand. See the example in the docstring.
David
def cpt2seg(file_name, sym=False, discrete=False):
 """Reads a .cpt palette and returns a segmented colormap.
 sym : If True, the returned colormap contains the palette and a mirrored
copy.
 For example, a blue-red-green palette would return a
blue-red-green-green-red-blue colormap.
 discrete : If true, the returned colormap has a fixed number of uniform
colors.
 That is, colors are not interpolated to form a continuous range.
 Example :
 >>> _palette_data = cpt2seg('palette.cpt')
 >>> palette = matplotlib.colors.LinearSegmentedColormap('palette',
_palette_data, 100)
 >>> imshow(X, cmap=palette)
 Licence: MIT
 Author: David Huard, 2006
 """
 dic = {}
 f = open(file_name, 'r')
 rgb = read_array(f)
 rgb = rgb/255.
 s = shape(rgb)
 colors = ['red', 'green', 'blue']
 for c in colors:
 i = colors.index(c)
 x = rgb[:, i+1]
 if discrete:
 if sym:
 dic[c] = zeros((2*s[0]+1, 3), float)
 dic[c][:,0] = linspace(0,1,2*s[0]+1)
 vec = concatenate((x ,x[::-1]))
 else:
 dic[c] = zeros((s[0]+1, 3), float)
 dic[c][:,0] = linspace(0,1,s[0]+1)
 vec = x
 dic[c][1:, 1] = vec
 dic[c][:-1,2] = vec
 else:
 if sym:
 dic[c] = zeros((2*s[0], 3), float)
 dic[c][:,0] = linspace(0,1,2*s[0])
 vec = concatenate((x ,x[::-1]))
 else:
 dic[c] = zeros((s[0], 3), float)
 dic[c][:,0] = linspace(0,1,s[0])
 vec = x
 dic[c][:, 1] = vec
 dic[c][:, 2] = vec
 return dic
2006年6月29日, James Boyle <bo...@ll...>:
>
> I am interested in producing a color map and accompanying colorbar with
> non-linear (arbitrary) spacing. My intent is like the attached color
> bar in which the increments are monotonic but vary in size. There might
> be an easy way to do this but it is not apparent to me.
>
> --Jim
>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
>
From: John P. <joh...@st...> - 2006年06月30日 07:55:40
I think this may be what you need
http://matplotlib.sourceforge.net/matplotlib.colors.html#LinearSegmentedColormap
As I recall there are some examples floating around somewhere, perhaps
on the wiki...
Cheers
JP
James Boyle wrote:
> I am interested in producing a color map and accompanying colorbar
> with non-linear (arbitrary) spacing. My intent is like the attached
> color bar in which the increments are monotonic but vary in size.
> There might be an easy way to do this but it is not apparent to me.
>
> --Jim
>
>------------------------------------------------------------------------
>
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> 
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Matplotlib-users mailing list
>Mat...@li...
>https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /