From: Ryan K. <rya...@gm...> - 2006-05-17 21:03:30
|
I am trying to create plots that look good in color or grayscale (I had asked about this before and was trying to write code with a switch - now I just want decent looking plots without having to switch - and I never really finished the with switching stuff either). I use the pylab interface and rely a lot on the default behavior for incrementing my colors when I overlay plots - i.e. I call plot different times with different data and it automatically makes the first one blue and the second green, ... How do I change the default color order and how do I set up a similar default linetype order, so that the first call to plot generates a solid line and the second a dashed one (for example). Thanks, Ryan |
From: Jouni K S. <jk...@ik...> - 2006-05-18 07:18:34
|
"Ryan Krauss" <rya...@gm...> writes: > How do I change the default color order The colors are hardwired in the pylab interface, but you can hack around it: gca()._get_lines.colors = ['#101050', '#105010', '#501010'] gca()._get_lines.Ncolors = 3 gca()._get_lines.firstColor = '#101050' Support for this might be a useful addition to the pylab interface. Does anyone know how to do this in Matlab? > and how do I set up a similar default linetype order, so that the > first call to plot generates a solid line and the second a dashed > one (for example). I don't think there is support for this in pylab. Of course, if all your plot calls just draw a single line, you can cycle both the color and the line style easily by defining your own function: my_colors = ['b','g','r']; my_styles = ['-', ':', '--'] my_c = 0; my_s = 0 def plot(x, y): global my_colors, my_styles, my_c, my_s pylab.plot(x, y, my_colors[my_c % len(my_colors)] + my_styles[my_s % len(my_styles)]) my_c += 1; my_s += 1 But if you want the full pylab.plot argument parsing functionality, the easiest thing would probably be to implement this in matplotlib.axis. -- Jouni |
From: Ryan K. <rya...@gm...> - 2006-05-18 12:23:31
|
Thanks Jouni. I can modify the color order using gca() and _getlines.colors, as you mentioned. But if I can't specify the line type in a similar fashion, then this approach isn't going to work for me. The trick with the other approach (with a global counter for how many lines are on the plot), is how to reset the counter for each new plot. gca()._get_lines.count seems to handle this problem by counting the lines already on the axis. (I wouldn't have known to poke around there if you had got me started.) So, unless a cleaner approach is suggested by someone else, I am going to follow an approach similar to Jouni's suggestion, only using gca()._get_lines.count+1 as the index to my global colors and line types list so that I am always calling plot (or actually semilogx) with explicit linetype specifications (like 'y-','b--',...) Any better ideas? Ryan On 5/18/06, Jouni K Seppanen <jk...@ik...> wrote: > "Ryan Krauss" <rya...@gm...> writes: > > > How do I change the default color order > > The colors are hardwired in the pylab interface, but you can hack > around it: > > gca()._get_lines.colors = ['#101050', '#105010', '#501010'] > gca()._get_lines.Ncolors = 3 > gca()._get_lines.firstColor = '#101050' > > Support for this might be a useful addition to the pylab interface. > Does anyone know how to do this in Matlab? > > > and how do I set up a similar default linetype order, so that the > > first call to plot generates a solid line and the second a dashed > > one (for example). > > I don't think there is support for this in pylab. > > Of course, if all your plot calls just draw a single line, you can > cycle both the color and the line style easily by defining your own > function: > > my_colors = ['b','g','r']; my_styles = ['-', ':', '--'] > my_c = 0; my_s = 0 > def plot(x, y): > global my_colors, my_styles, my_c, my_s > pylab.plot(x, y, my_colors[my_c % len(my_colors)] > + my_styles[my_s % len(my_styles)]) > my_c += 1; my_s += 1 > > But if you want the full pylab.plot argument parsing functionality, > the easiest thing would probably be to implement this in > matplotlib.axis. > > -- > Jouni > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: Ryan K. <rya...@gm...> - 2006-05-18 12:49:11
|
There is a serious flaw to my approach. It seems that if plot is called with an explicit linetype like 'b-', then ax._get_lines.count is not automatically incremented. Ryan On 5/18/06, Ryan Krauss <rya...@gm...> wrote: > Thanks Jouni. > > I can modify the color order using gca() and _getlines.colors, as you > mentioned. But if I can't specify the line type in a similar fashion, > then this approach isn't going to work for me. > > The trick with the other approach (with a global counter for how many > lines are on the plot), is how to reset the counter for each new plot. > gca()._get_lines.count seems to handle this problem by counting the > lines already on the axis. (I wouldn't have known to poke around > there if you had got me started.) > > So, unless a cleaner approach is suggested by someone else, I am going > to follow an approach similar to Jouni's suggestion, only using > gca()._get_lines.count+1 as the index to my global colors and line > types list so that I am always calling plot (or actually semilogx) > with explicit linetype specifications (like 'y-','b--',...) > > Any better ideas? > > Ryan > > On 5/18/06, Jouni K Seppanen <jk...@ik...> wrote: > > "Ryan Krauss" <rya...@gm...> writes: > > > > > How do I change the default color order > > > > The colors are hardwired in the pylab interface, but you can hack > > around it: > > > > gca()._get_lines.colors = ['#101050', '#105010', '#501010'] > > gca()._get_lines.Ncolors = 3 > > gca()._get_lines.firstColor = '#101050' > > > > Support for this might be a useful addition to the pylab interface. > > Does anyone know how to do this in Matlab? > > > > > and how do I set up a similar default linetype order, so that the > > > first call to plot generates a solid line and the second a dashed > > > one (for example). > > > > I don't think there is support for this in pylab. > > > > Of course, if all your plot calls just draw a single line, you can > > cycle both the color and the line style easily by defining your own > > function: > > > > my_colors = ['b','g','r']; my_styles = ['-', ':', '--'] > > my_c = 0; my_s = 0 > > def plot(x, y): > > global my_colors, my_styles, my_c, my_s > > pylab.plot(x, y, my_colors[my_c % len(my_colors)] > > + my_styles[my_s % len(my_styles)]) > > my_c += 1; my_s += 1 > > > > But if you want the full pylab.plot argument parsing functionality, > > the easiest thing would probably be to implement this in > > matplotlib.axis. > > > > -- > > Jouni > > > > > > > > ------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, security? > > Get stuff done quickly with pre-integrated technology to make your job easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > > Matplotlib-users mailing list > > Mat...@li... > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > |
From: Ryan K. <rya...@gm...> - 2006-05-18 13:20:24
|
However, calling plot with color and linestyle keyword args instead of 'b-' in args leads to incrementing the line count, and things seem to be working. (I had actually written a little line count incrementing function and then had to take it out when I wanted to specify rgb values and switched to the kwargs). Ryan On 5/18/06, Ryan Krauss <rya...@gm...> wrote: > There is a serious flaw to my approach. It seems that if plot is > called with an explicit linetype like 'b-', then ax._get_lines.count > is not automatically incremented. > > Ryan > > On 5/18/06, Ryan Krauss <rya...@gm...> wrote: > > Thanks Jouni. > > > > I can modify the color order using gca() and _getlines.colors, as you > > mentioned. But if I can't specify the line type in a similar fashion, > > then this approach isn't going to work for me. > > > > The trick with the other approach (with a global counter for how many > > lines are on the plot), is how to reset the counter for each new plot. > > gca()._get_lines.count seems to handle this problem by counting the > > lines already on the axis. (I wouldn't have known to poke around > > there if you had got me started.) > > > > So, unless a cleaner approach is suggested by someone else, I am going > > to follow an approach similar to Jouni's suggestion, only using > > gca()._get_lines.count+1 as the index to my global colors and line > > types list so that I am always calling plot (or actually semilogx) > > with explicit linetype specifications (like 'y-','b--',...) > > > > Any better ideas? > > > > Ryan > > > > On 5/18/06, Jouni K Seppanen <jk...@ik...> wrote: > > > "Ryan Krauss" <rya...@gm...> writes: > > > > > > > How do I change the default color order > > > > > > The colors are hardwired in the pylab interface, but you can hack > > > around it: > > > > > > gca()._get_lines.colors = ['#101050', '#105010', '#501010'] > > > gca()._get_lines.Ncolors = 3 > > > gca()._get_lines.firstColor = '#101050' > > > > > > Support for this might be a useful addition to the pylab interface. > > > Does anyone know how to do this in Matlab? > > > > > > > and how do I set up a similar default linetype order, so that the > > > > first call to plot generates a solid line and the second a dashed > > > > one (for example). > > > > > > I don't think there is support for this in pylab. > > > > > > Of course, if all your plot calls just draw a single line, you can > > > cycle both the color and the line style easily by defining your own > > > function: > > > > > > my_colors = ['b','g','r']; my_styles = ['-', ':', '--'] > > > my_c = 0; my_s = 0 > > > def plot(x, y): > > > global my_colors, my_styles, my_c, my_s > > > pylab.plot(x, y, my_colors[my_c % len(my_colors)] > > > + my_styles[my_s % len(my_styles)]) > > > my_c += 1; my_s += 1 > > > > > > But if you want the full pylab.plot argument parsing functionality, > > > the easiest thing would probably be to implement this in > > > matplotlib.axis. > > > > > > -- > > > Jouni > > > > > > > > > > > > ------------------------------------------------------- > > > Using Tomcat but need to do more? Need to support web services, security? > > > Get stuff done quickly with pre-integrated technology to make your job easier > > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > _______________________________________________ > > > Matplotlib-users mailing list > > > Mat...@li... > > > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > > |
From: John H. <jdh...@ac...> - 2006-05-18 14:08:46
|
>>>>> "Ryan" == Ryan Krauss <rya...@gm...> writes: Ryan> There is a serious flaw to my approach. It seems that if Ryan> plot is called with an explicit linetype like 'b-', then Ryan> ax._get_lines.count is not automatically incremented. You should never use an underscore variable since the leading underscore basically indicates this is an internal variable and it could be removed or changes at any point w/o documentation. If something changes in the "public" API, it will at least be documented in the API_CHANGES file. I think your best approach is to write some helper classes rather than try and set the matplotlib defaults from mycyclers import colorcycler, linecycler for data in mydata: ax.plot(data, linestyle=linecycler(), color=colorcycler()) where linecycler and colorcycler are generators of some sort. Rhen you can alter your linecycler and colorcycler to do whatever you want, make different defaults for color or grayscale, etc... I'm not opposed to making the default linestyles and colorcycles configurable, it has come up a few times, but it may be easier and quicker for you just to code up some custom classes or functions that have just the behavior you want. JDH |