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