overriding default color order and linetypes

"Ryan Krauss" <ryanlists@...287...> 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

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 <jks@...397...> wrote:

"Ryan Krauss" <ryanlists@...287...> 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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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 <ryanlists@...287...> 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 <jks@...397...> wrote:
> "Ryan Krauss" <ryanlists@...287...> 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
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

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 <ryanlists@...287...> 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 <ryanlists@...287...> 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 <jks@...397...> wrote:
> > "Ryan Krauss" <ryanlists@...287...> 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
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>