P.R. wrote:
> Hi,
> I'd like to generate a colormap index based on an array of levels & using an
> existing colormap (Spectral).
> However, Id like the cmap index to start at the 0.3 value of the Spectral
> scale (orange/yellow area) instead of starting at the '0' scale value (red
> area), and then continue until the 0.8 value area (green)...in essence, Id
> like to do a 'slice' of a given colormap, using BoundaryNorm or some other
> function, and using my levels array in order to break up the colormap.
> 
> What would be the best way to get this done?
> Can it be easily done using existing functions, or would I need to create my
> own colormap?

One way is to extract the colors you want from spectral, and use them 
with a boundary norm.  Suppose you want 10 colors because you have 11 
boundaries, and suppose they are in the range from 20 to 30:


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm


boundaries = np.linspace(20, 30, 11)
colors = cm.spectral(np.linspace(0.3, 0.8, 10))
cmap = mcolors.ListedColormap(colors)
norm = mcolors.BoundaryNorm(boundaries, cmap.N)

z = 20 + np.random.rand(10,20)*10
plt.imshow(z, cmap=cmap, norm=norm)
plt.colorbar()
plt.show()

So yes, you are creating your own colormap, but it is easy.

Eric

> 
> Please help,
> 
> Thanks,
> P.Romero
> 
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with 
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to