|
From: antonv <vas...@ya...> - 2009-01-16 16:33:20
|
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. |
|
From: John H. <jd...@gm...> - 2009-01-16 17:11:26
|
On Fri, Jan 16, 2009 at 10:33 AM, antonv <vas...@ya...> 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 |
|
From: antonv <vas...@ya...> - 2009-01-17 04:11:51
|
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 <vas...@ya...> > 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 > Mat...@li... > 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. |
|
From: Eric F. <ef...@ha...> - 2009-01-17 04:34:55
|
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://sourceforge.net/svn/?group_id=80706 http://subversion.tigris.org/ Eric > > > John Hunter-4 wrote: >> On Fri, Jan 16, 2009 at 10:33 AM, antonv <vas...@ya...> >> 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 >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> > |
|
From: antonv <vas...@ya...> - 2009-01-17 04:39:54
|
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? > > http://sourceforge.net/svn/?group_id=80706 > http://subversion.tigris.org/ > > Eric > >> >> >> John Hunter-4 wrote: >>> On Fri, Jan 16, 2009 at 10:33 AM, antonv <vas...@ya...> >>> 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 >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> >>> >> > > > ------------------------------------------------------------------------------ > 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 > Mat...@li... > 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. |
|
From: John H. <jd...@gm...> - 2009-01-17 12:50:37
|
On Fri, Jan 16, 2009 at 10:34 PM, Eric Firing <ef...@ha...> 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? > > http://sourceforge.net/svn/?group_id=80706 > http://subversion.tigris.org/ See also http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn JDH |
|
From: Eric F. <ef...@ha...> - 2009-01-17 04:48:38
|
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? >> http://sourceforge.net/svn/?group_id=80706 >> http://subversion.tigris.org/ |