[Matplotlib-users] define color cycle in matplotlibrc

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg14772.html

The above thread includes two reasonable requests:

1) add color cycle as an rcParam

2) add a line style cycle as well

The first of these is easier to implement, although it requires a bit more than the patch provided. Questions:

1) Should the the color_cycle be in the axes group? Although it affects lines, it is defined only at the Axes level, and affects only lines drawn by plot.

Alternative: since it affects only plot, should there be a new "plot" group to make that explicit, so it would be rcParams['plot.color_cycle']?

2) It was pointed out that there is a strange connection between the color cycle and the lines.color rcParam. This connection looks to me like a bit of legacy that can be dropped with little risk of pain in user land, since the default would still be to have the initial color in the cycle (blue) be the same as the default lines.color (blue). The proposed difference is that setting lines.color would have no effect on the color_cycle, and vice-versa. John, I think the present connection dates all the way back to your work around svn r500 or so; please tell me if there is some compelling reason to keep it. It appears to me that breaking the connection would make both the code and the actual mpl behavior simpler and less surprising, with no loss of useful functionality.

3) Would it make sense to add color_cycle to the Axes API, so that it can be set directly for a given axes as an alternative to going through the rc mechanism? Right now it can be set via a function, but must be set before Axes creation; this doesn't make sense to me. It would make more sense as an Axes property that could be set at any time, and would apply to subsequent calls to plot.

My sense is that as a matter of design strategy, whenever possible, one should be able to use the API, via properties, methods, or functions, to locally set any options for which rcParams gives the global default values.

Eric

1) Should the the color_cycle be in the axes group? Although it affects
lines, it is defined only at the Axes level, and affects only lines drawn by
plot.

Alternative: since it affects only plot, should there be a new "plot" group
to make that explicit, so it would be rcParams['plot.color_cycle']?

I think it is better to do at the Axes level, because even if plot is
the only command to do this now, I could imagine others commands
wanting to use it (fill_between, bar?). I have had people asking me
just for access to the list so they could use it for some purpose or
another, so having the list easily accessible is desirable.

2) It was pointed out that there is a strange connection between the color
cycle and the lines.color rcParam. This connection looks to me like a bit
of legacy that can be dropped with little risk of pain in user land, since
the default would still be to have the initial color in the cycle (blue) be
the same as the default lines.color (blue). The proposed difference is that
setting lines.color would have no effect on the color_cycle, and vice-versa.
John, I think the present connection dates all the way back to your work
around svn r500 or so; please tell me if there is some compelling reason to
keep it. It appears to me that breaking the connection would make both the
code and the actual mpl behavior simpler and less surprising, with no loss
of useful functionality.

I think deprecating lines.color and making the first element of the
cycle be the default color makes the most sense.

3) Would it make sense to add color_cycle to the Axes API, so that it can be
set directly for a given axes as an alternative to going through the rc
mechanism? Right now it can be set via a function, but must be set before
Axes creation; this doesn't make sense to me. It would make more sense as
an Axes property that could be set at any time, and would apply to
subsequent calls to plot.

It might be best to make this a class level attribute, that way people
can tweak it globally or at the instance level, and have access to the
list *before* the Axes instance is created. The downside of this is it
falls outside of the usual properties pattern that people can access
via the normal introspection facilities.

The linestyles cycle question is as you say a good bit harder, and
would best be served by having some sort of configurable color scheme,
where one could set grayscale or something like that to get default
black/white/gray colors and styles for the cycle.

JDH

···

On Sun, Jan 3, 2010 at 2:39 PM, Eric Firing <efiring@...229...> wrote:

2) It was pointed out that there is a strange connection between the color
cycle and the lines.color rcParam. This connection looks to me like a bit
of legacy that can be dropped with little risk of pain in user land, since
the default would still be to have the initial color in the cycle (blue) be
the same as the default lines.color (blue). The proposed difference is that
setting lines.color would have no effect on the color_cycle, and vice-versa.
John, I think the present connection dates all the way back to your work
around svn r500 or so; please tell me if there is some compelling reason to
keep it. It appears to me that breaking the connection would make both the
code and the actual mpl behavior simpler and less surprising, with no loss
of useful functionality.

I think deprecating lines.color and making the first element of the
cycle be the default color makes the most sense.

The only problem is that lines.color is the default for LineCollection and Line2D, both of which are fairly separate from Axes, so having them default to rcParams['axes.color_cycle'][0] seems a little odd.

Eric

Yes, I was worrying about the same thing while cooking dinner :slight_smile: A
line can be added to a Figure or an Axes, so perhaps the default color
should not come from there. What about a module level attribute
matplotlib.colors.cycle by an rc param "colors.cycle" and then the
default Line2D and LineCollection color can default to
matplotlib.colors.cycle[0].

···

On Sun, Jan 3, 2010 at 3:54 PM, Eric Firing <efiring@...229...> wrote:

The only problem is that lines.color is the default for LineCollection and
Line2D, both of which are fairly separate from Axes, so having them default
to rcParams['axes.color_cycle'][0] seems a little odd.

John Hunter wrote:

The only problem is that lines.color is the default for LineCollection and
Line2D, both of which are fairly separate from Axes, so having them default
to rcParams['axes.color_cycle'][0] seems a little odd.

Yes, I was worrying about the same thing while cooking dinner :slight_smile: A
line can be added to a Figure or an Axes, so perhaps the default color
should not come from there. What about a module level attribute
matplotlib.colors.cycle by an rc param "colors.cycle" and then the
default Line2D and LineCollection color can default to
matplotlib.colors.cycle[0].

We could, but I don't see any advantage over leaving it the way I made it a few minutes ago, which leaves lines.color independent of the axes-level cycle. It seems to me that color-cycling is quite different from setting a default color for something like Line2D, and there is no reason they should be connected via the first element of a list. Maybe this would need to be revisited as part of the API layer redesign that you sketched out once, but that we still haven't gotten around to advancing.

The idea of a rename to colors.cycle has some appeal, except that as it is used, it really is Axes-specific, and appears uniquely at the Axes level.

Eric

···

On Sun, Jan 3, 2010 at 3:54 PM, Eric Firing <efiring@...229...> wrote: