colormap shift

Hi all,

I am a newbie in matplotlib and I'd like to use colormap for z-axis. I
can use in basic mode but would like to shift the existed colormap -
binary - for using in this way:

i would not like to set the white color for z=0.0 For describing: I
would like to use the binary colormap but without the white color
because this color I would like to leave for not-defined value for
(x,y).

Is it possible to do this? Maybe create new colormap on the basis of
the "binary" but without the white color.

Any suggestions?

Thanks in advance for your help.

best,
Marian

I asked same question with different problem here: http://matplotlib.1069221.n5.nabble.com/How-to-shift-colormap-td18451.html

You can see there how to use Gimp and create mpl colormap and then later there is nifty code that will allow you to shift colormaps with a slider

From your problem I assume you would want the first.

Here is ready made for you:

···

========================================
import matplotlib as mpl
import matplotlib.pyplot as plt

ccm = {
‘red’ : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
),
‘green’ : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
),
‘blue’ : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
)
}

cm = mpl.colors.LinearSegmentedColormap(‘my_map’, ccm)

from numpy import outer, arange, ones
a = outer(arange(0, 1, 0.01), ones(10))

plt.imshow(a, cmap=cm)
plt.show()

Nice! I couldn't resist doing a Sage interact version of the slider thing:

Thanks,

Jason

···

On 11/5/12 3:50 PM, klo uo wrote:

You can see there how to use Gimp and create mpl colormap and then later
there is nifty code that will allow you to shift colormaps with a slider

--
Jason Grout

Thanks for your reply. It's really nice. But, can you provide the code
(part of it) where the colormap start from "very light gray" to "black"
in the range (0,1). And all of the points >1 are black one and =0.0 IS
NOT white. I have 2D map with defined pair (x,y) and the values for
them, but also there are the pairs where I defined the value out of
range (z=5.). So I would like to show the 2D map in grayscale ((x,y),z)
but use WHITE color for z=5. Because when I set "cm.set_over('white')"
and the white is also for z=0.0 (not shifted colormap), you can't
distinguish these values - if it is z=5 or z=0. Of course, the possible
way is to use rgb colormaps (not grayscale) but I can't do it because I
need BW version of the figure.

Thanks in advance for your help.

Dňa Mon, 5 Nov 2012 22:50:31 +0100
klo uo <klonuo@...287...> napísal:

···

I asked same question with different problem here:
http://matplotlib.1069221.n5.nabble.com/How-to-shift-colormap-td18451.html

You can see there how to use Gimp and create mpl colormap and then later
there is nifty code that will allow you to shift colormaps with a slider

>From your problem I assume you would want the first.

Here is ready made for you:

========================================
import matplotlib as mpl
import matplotlib.pyplot as plt

ccm = {
'red' : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
),
'green' : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
),
'blue' : (
(0.000000, 0.000000, 0.000000),
(0.000001, 1.000000, 1.000000),
(0.500000, 0.500000, 0.500000),
(1.000000, 0.000000, 0.000000)
)
}

cm = mpl.colors.LinearSegmentedColormap('my_map', ccm)

from numpy import outer, arange, ones
a = outer(arange(0, 1, 0.01), ones(10))

plt.imshow(a, cmap=cm)
plt.show()

Hi, I once was indicated a way to extract colors from exsiting colormaps:

I just answered a question on Stackoverflow and maybe you can have a look.

all code in pylab mode

a = np.arange(100).reshape(10,10)
#here is the image with white and black end
imshow(a,cmap=mat.cm.binary)
colorbar()

#we extract only the 0.2-->0.7 part of original colormap and make a new one
#so that the white and black end are removed
rgba_array = mat.cm.binary(np.linspace(0,1,num=10,endpoint=True))
extract_rgba_array_255 = rgba_array[2:8,0:3]
imshow(a,cmap=mat.colors.ListedColormap(extract_rgba_array_255))
colorbar()

cheers,

Chao

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/colormap-shift-tp39660p39707.html
Sent from the matplotlib - users mailing list archive at Nabble.com.