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
get your head around, it is pretty easy.

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

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

···

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
get your head around, it is pretty easy.

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

See also
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.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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

http://subversion.tigris.org/

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
get your head around, it is pretty easy.

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

See also
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.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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?

matplotlib download | SourceForge.net
http://subversion.tigris.org/

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
get your head around, it is pretty easy.

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

See also
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.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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

matplotlib download | SourceForge.net
http://subversion.tigris.org/

See also

  http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

JDH

···

On Fri, Jan 16, 2009 at 10:34 PM, Eric Firing <efiring@...202...> 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?

matplotlib download | SourceForge.net
http://subversion.tigris.org/