Repository navigation
Description
In the 2.x branch, the recent addition of the CN feature also added an implicit assumption that "color" will always be in the property cycle. This conflicts with the feature of prop_cycle that it only advances for a plotting function if the user does not specify at least one of the properties made available by the property cycle.
This is important because several plotting functions will make multiple calls to plot()/fill() under the hood, but should have already advanced the cycle. Also, this mimics pre-1.5 behavior of the color_cycle where it did not advance if color was already specified.
The test (which is currently being modified to paper over the problem) which noticed this change is the following:
fig, ax = plt.subplots()
ax.set_prop_cycle('linewidth', [2, 4])
for c in range(1, 4):
ax.plot(np.arange(10), c * np.arange(10), lw=0.1)
ax.plot(np.arange(10), 4 * np.arange(10))
ax.plot(np.arange(10), 5 * np.arange(10))
In the v1.5.x branch, this would result in the cycler not being advanced for the first three lines, and then two lines are made with linewidths of 2 and 4 in that order. In 2.x branch, the cycler gets advanced because of the implicit inclusion of "color" to the property cycle. Therefore, the cycler has a property which is not specified by the user, and it thinks it needs to advance itself. This results in a plot that has three thin lines and then a line of width 4 and then 2 (because of the odd number of plot calls prior).
Now, consider the following scenario:
fig, ax = plt.subplots()
ax.set_prop_cycle('color', 'rb')
for c in range(1, 4):
ax.plot(np.arange(10), c * np.arange(10), color='k')
ax.plot(np.arange(10), 4 * np.arange(10))
ax.plot(np.arange(10), 5 * np.arange(10))
In this case, the cycler will not advance for the first three plots, but will for the last two -- as expected. This difference in behavior will cause confusion among users, and will be very difficult to explain.
I shall re-iterate my design concept behind the property-cycle feature that I added for v1.5: "Color is not special!". I am fine with having a failover mechanism for "C0" in the case that color isn't in the cycler, but to actually modify the cycler provided by the user only leads to confusion. What would we do when we want to expand the "CN" notation to other properties? Are we going to start implicitly include them into the property cycle as well?
Activity
tacaswell commentedon May 23, 2016
Trying to address this brought up an other corner case.
In the test we do
so if we remove the implicit color
plotfalls back toC0which in thecolormodule looks at the prop_cycle inrcparams.I think this is just a wart of how this, as the
C0explicitly is a global thing. If you want to change the meaning you have to use a context manager.The other option is to start injecting cyclers into every call to
to_rgbawhich seems less than good.efiring commentedon May 23, 2016
On 2016/05/22 5:37 PM, Thomas A Caswell wrote:
I'm not sure I see how this is a problem--do you mean it is because the
user is expecting to see plot use the full cycle from rcparams, but
instead it keeps repeating the C0 from rcparams? Or the user is
expecting facecolor to override the missing color?
Downright unacceptable.
tacaswell commentedon May 23, 2016
If the user sets an axes level prop cycle, the CN notation will still refer
to the global prop cycle which could be confusing.
We could also move some if the color conversion machinery to the axes
objects to give them a chance to deal with the CN before it gets resolved
globally.
On Mon, May 23, 2016, 00:04 Eric Firing notifications@github.com wrote:
efiring commentedon May 28, 2016
Would it be possible to add a cycler kwarg to
to_rgbaandto_rgba_array? If None, the rcParams cycler would be used. Every call to one of these functions from a function with an Axes would substitute the cycler from that Axes.tacaswell commentedon May 28, 2016
That seems reasonable to me.
attn @anntzer
anntzer commentedon May 29, 2016
Actually I have no idea of what's happening in the "interesting" block of
to_rgba:which I just copy-pasted from the previous implementation... so I'll let someone else take care of it.
efiring commentedon May 29, 2016
@tacaswell, that block of code looks a little odd: if there is neither a 'axes.prop_cycle' nor a 'axes.color_cycle',
prop_cyclerwill be None, and the call to._transpose()will fail. Does this need to be trapped with a more informative exception? If rcsetup guarantees that this cannot occur, then a comment to that effect would be helpful. Actually, if that is the case, then the test for'axes.color_cycle' in rcParamsis not needed.tacaswell commentedon May 29, 2016
The rc validation means
rcParams['axes.prop_cycle']can never beNone. Would we want to fall back to the color cycle if color is not inprop_cycle? I think not because that means the user changed the defaultprop_cycleand we should respect that.tacaswell commentedon May 30, 2016
closed by #6499