From: per f. <per...@gm...> - 2009-07-14 13:51:31
|
Hi all, i would like to set the colors of the lines i plot (using the plot function) to go from red to blue, in evenly spaced interval. that is, imagine a color map from red to green, where i plot n-many lines, each receiving a color from this color map, starting at the red end and going to green. the docs say how to set the color cycle of lines set by plot, using: matplotlib.axes.set_default_color_cycle(['r', 'y', 'g', 'b']) but this only allows me to use named colors, and here i am looking to use shades from red to green. my question is: first, how can i generate N evenly spaced colors from the red spectrum to the green spectrum? and two, how can i make it so plot uses these colors for its line plots? thanks very much. |
From: Tony S Yu <to...@MI...> - 2009-07-14 14:14:30
|
Not too long ago, I posted an example of this to the list. The code near the bottom of that thread is a little more general than the one at the top and shows, three different ways to cycle through the colors of a colormap. Hope that helps, -Tony On Jul 14, 2009, at 9:51 AM, per freem wrote: > Hi all, > > i would like to set the colors of the lines i plot (using the plot > function) to go from red to blue, in evenly spaced interval. that > is, imagine a color map from red to green, where i plot n-many > lines, each receiving a color from this color map, starting at the > red end and going to green. > > the docs say how to set the color cycle of lines set by plot, using: > > matplotlib.axes.set_default_color_cycle(['r', 'y', 'g', 'b']) > > but this only allows me to use named colors, and here i am looking > to use shades from red to green. > my question is: first, how can i generate N evenly spaced colors > from the red spectrum to the green spectrum? and two, how can i make > it so plot uses these colors for its line plots? > > thanks very much. > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited > time, > vendors submitting new applications to BlackBerry App World(TM) will > have > the opportunity to enter the BlackBerry Developer Challenge. See > full prize > details at: http://p.sf.net/sfu/Challenge_______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: per f. <per...@gm...> - 2009-07-14 19:13:00
|
Hi Tony, thanks for the pointer. that code does not run for me, it generates the following error: ttributeError Traceback (most recent call last) color_cycle.py in <module>() 63 if __name__ == '__main__': 64 n_lines = 10 ---> 65 cycle_cmap(length=n_lines) 66 x = np.linspace(0, 10) 67 for shift in np.linspace(0, np.pi, n_lines): color_cycle.py in cycle_cmap(cmap, length) 59 idx = np.linspace(crange['start'], crange['stop'], length).astype(np.int) 60 colors = cm(idx) ---> 61 mpl.axes.set_default_color_cycle(colors.tolist()) 62 63 if __name__ == '__main__': /Library/Python/2.5/site-packages/matplotlib/axes.pyc in set_default_color_cycle(clist) 113 """ 114 _process_plot_var_args.defaultColors = clist[:] --> 115 rcParams['lines.color'] = clist[0] 116 117 class _process_plot_var_args: /Library/Python/2.5/site-packages/matplotlib/__init__.pyc in __setitem__(self, key, val) 603 instead.'% (key, alt)) 604 key = alt --> 605 cval = self.validate[key](val) 606 dict.__setitem__(self, key, cval) 607 except KeyError: /Library/Python/2.5/site-packages/matplotlib/rcsetup.pyc in validate_color(s) 160 def validate_color(s): 161 'return a valid color arg' --> 162 if s.lower() == 'none': 163 return 'None' 164 if is_color_like(s): AttributeError: 'list' object has no attribute 'lower' WARNING: Failure executing file: <color_cycle.py> any idea what might be wrong? On Tue, Jul 14, 2009 at 10:14 AM, Tony S Yu <to...@mi...> wrote: > Not too long ago, I posted an example of this to the list<http://www.nabble.com/Where-to-post-examples-%2528specifically%252C-one-that-may-be-useful-for-time-evolution-plots%2529-td23901837.html>. > The code near the bottom of that thread is a little more general than the > one at the top and shows, three different ways to cycle through the colors > of a colormap. > > Hope that helps, > -Tony > > > On Jul 14, 2009, at 9:51 AM, per freem wrote: > > Hi all, > > i would like to set the colors of the lines i plot (using the plot > function) to go from red to blue, in evenly spaced interval. that is, > imagine a color map from red to green, where i plot n-many lines, each > receiving a color from this color map, starting at the red end and going to > green. > > the docs say how to set the color cycle of lines set by plot, using: > > matplotlib.axes.set_default_color_cycle(['r', 'y', 'g', 'b']) > > but this only allows me to use named colors, and here i am looking to use > shades from red to green. > my question is: first, how can i generate N evenly spaced colors from the > red spectrum to the green spectrum? and two, how can i make it so plot uses > these colors for its line plots? > > thanks very much. > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > > details at: > http://p.sf.net/sfu/Challenge_______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > |
From: Tony S Yu <to...@MI...> - 2009-07-14 19:35:59
|
On Jul 14, 2009, at 3:12 PM, per freem wrote: > Hi Tony, > > thanks for the pointer. that code does not run for me, it generates > the following error: > > ttributeError Traceback (most recent call > last) > .... > > /Library/Python/2.5/site-packages/matplotlib/rcsetup.pyc in > validate_color(s) > 160 def validate_color(s): > 161 'return a valid color arg' > --> 162 if s.lower() == 'none': > 163 return 'None' > 164 if is_color_like(s): > > AttributeError: 'list' object has no attribute 'lower' > WARNING: Failure executing file: <color_cycle.py> > > any idea what might be wrong? Hmm, it looks like there was a fix added a couple of months ago (svn revision 7164). If you're on trunk, then updating it should fix this problem. If you're not on trunk: I don't think any official releases have occurred since this fix, so I don't think updating to the last official release will help. In any case, I think this error only affects the ``cycle_cmap`` function in the code (calls to ``cmap_intervals`` should work fine). If you comment out the 4 lines of code after the comment "Change the default color cycle", I believe everything should work fine. -Tony |
From: John [H2O] <was...@gm...> - 2009-07-15 13:48:52
|
I also recently posted an example that may do something similar to what you are after, you can have a look here: http://www.nabble.com/contribute-to-gallery--Or%2C-just-advice-on-changing-colors-automagically....-td24419101.html#a24427781 per freem-2 wrote: > > Hi all, > > i would like to set the colors of the lines i plot (using the plot > function) > to go from red to blue, in evenly spaced interval. that is, imagine a > color > map from red to green, where i plot n-many lines, each receiving a color > from this color map, starting at the red end and going to green. > > the docs say how to set the color cycle of lines set by plot, using: > > matplotlib.axes.set_default_color_cycle(['r', 'y', 'g', 'b']) > > but this only allows me to use named colors, and here i am looking to use > shades from red to green. > my question is: first, how can i generate N evenly spaced colors from the > red spectrum to the green spectrum? and two, how can i make it so plot > uses > these colors for its line plots? > > thanks very much. > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full > prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://www.nabble.com/question-about-setting-colors-of-lines-using-colormap-tp24479842p24498248.html Sent from the matplotlib - users mailing list archive at Nabble.com. |