 # cmap from sepparate color values

I have a series of 18 separate colors to create my cmap but I would like to
convert that to a continuous map which interpolates all the other values in
between my chosen colors. This should be really easy but I am not sure how
can it be solved. Any ideas?

Thanks,
Anton

···

--
View this message in context: http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21503197.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Although the logic of the LinearSegmentedColormap takes some time to

Here is an example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
colors = 'red', 'green', 'blue', 'yellow', 'orange'

ncolors = len(colors)

vals = np.linspace(0., 1., ncolors)

cdict = dict(red=[], green=[], blue=[])
for val, color in zip(vals, colors):
r,g,b = mcolors.colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))

cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)

x = np.arange(10000.).reshape((100,100))

plt.imshow(x, cmap=cmap)

plt.show()

I just added a function to svn to support this, so with svn you can
do

colors = 'red', 'gray', 'green'
cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
X, Y = np.meshgrid(np.arange(10), np.arange(10))
plt.imshow(X+Y, cmap=cmap)

JDH

···

On Fri, Jan 16, 2009 at 10:33 AM, antonv <vasilescu_anton@...9...> wrote:

I have a series of 18 separate colors to create my cmap but I would like to
convert that to a continuous map which interpolates all the other values in
between my chosen colors. This should be really easy but I am not sure how
can it be solved. Any ideas?

Thanks for the quick reply John! Now it makes a lot more sense. The next dumb
question is what is SVN and where can I find more bout it?

John Hunter-4 wrote:

···

On Fri, Jan 16, 2009 at 10:33 AM, antonv <vasilescu_anton@...9...> > wrote:

I have a series of 18 separate colors to create my cmap but I would like
to
convert that to a continuous map which interpolates all the other values
in
between my chosen colors. This should be really easy but I am not sure
how
can it be solved. Any ideas?

Although the logic of the LinearSegmentedColormap takes some time to

http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

Here is an example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
colors = 'red', 'green', 'blue', 'yellow', 'orange'

ncolors = len(colors)

vals = np.linspace(0., 1., ncolors)

cdict = dict(red=[], green=[], blue=[])
for val, color in zip(vals, colors):
r,g,b = mcolors.colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))

cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)

x = np.arange(10000.).reshape((100,100))

plt.imshow(x, cmap=cmap)

plt.show()

http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
I just added a function to svn to support this, so with svn you can
do

colors = 'red', 'gray', 'green'
cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
X, Y = np.meshgrid(np.arange(10), np.arange(10))
plt.imshow(X+Y, cmap=cmap)

JDH

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21512920.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Thanks for the quick reply John! Now it makes a lot more sense. The next dumb
question is what is SVN and where can I find more bout it?

Eric

···

John Hunter-4 wrote:

On Fri, Jan 16, 2009 at 10:33 AM, antonv <vasilescu_anton@...9...> >> wrote:

I have a series of 18 separate colors to create my cmap but I would like
to
convert that to a continuous map which interpolates all the other values
in
between my chosen colors. This should be really easy but I am not sure
how
can it be solved. Any ideas?

Although the logic of the LinearSegmentedColormap takes some time to

http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

Here is an example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
colors = 'red', 'green', 'blue', 'yellow', 'orange'

ncolors = len(colors)

vals = np.linspace(0., 1., ncolors)

cdict = dict(red=[], green=[], blue=[])
for val, color in zip(vals, colors):
r,g,b = mcolors.colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))

cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)

x = np.arange(10000.).reshape((100,100))

plt.imshow(x, cmap=cmap)

plt.show()

http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
I just added a function to svn to support this, so with svn you can
do

colors = 'red', 'gray', 'green'
cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
X, Y = np.meshgrid(np.arange(10), np.arange(10))
plt.imshow(X+Y, cmap=cmap)

JDH

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks again! That looks cool and seems that it can be used it to a lot of
other projects I have going on!

Anton

efiring wrote:

···

antonv wrote:

Thanks for the quick reply John! Now it makes a lot more sense. The next
dumb
question is what is SVN and where can I find more bout it?

Eric

John Hunter-4 wrote:

On Fri, Jan 16, 2009 at 10:33 AM, antonv <vasilescu_anton@...9...> >>> wrote:

I have a series of 18 separate colors to create my cmap but I would
like
to
convert that to a continuous map which interpolates all the other
values
in
between my chosen colors. This should be really easy but I am not sure
how
can it be solved. Any ideas?

Although the logic of the LinearSegmentedColormap takes some time to

http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

Here is an example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
colors = 'red', 'green', 'blue', 'yellow', 'orange'

ncolors = len(colors)

vals = np.linspace(0., 1., ncolors)

cdict = dict(red=[], green=[], blue=[])
for val, color in zip(vals, colors):
r,g,b = mcolors.colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))

cmap = mcolors.LinearSegmentedColormap('mycolors', cdict)

x = np.arange(10000.).reshape((100,100))

plt.imshow(x, cmap=cmap)

plt.show()

http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html.
I just added a function to svn to support this, so with svn you can
do

colors = 'red', 'gray', 'green'
cmap = mcolors.LinearSegmentedColormap.from_list('mycolors', colors)
X, Y = np.meshgrid(np.arange(10), np.arange(10))
plt.imshow(X+Y, cmap=cmap)

JDH

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/cmap-from-sepparate-color-values-tp21503197p21513073.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Thanks again! That looks cool and seems that it can be used it to a lot of
other projects I have going on!

If you are looking for something to use for your own projects, I recommend not svn but one of the more modern distributed vcs systems: mercurial (hg), bzr, or git. I use and like mercurial:

http://www.selenic.com/mercurial/wiki/

Eric

···

Anton

efiring wrote:

antonv wrote:

Thanks for the quick reply John! Now it makes a lot more sense. The next
dumb
question is what is SVN and where can I find more bout it?