Skip to content

prop_cycle breaks keyword aliases #6343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lkluft opened this issue Apr 28, 2016 · 8 comments
Closed

prop_cycle breaks keyword aliases #6343

lkluft opened this issue Apr 28, 2016 · 8 comments
Assignees
Milestone

Comments

@lkluft
Copy link

lkluft commented Apr 28, 2016

Debian GNU/Linux 6.0.10 (squeeze) and OSX 10.11.4, Python 3.5.1, matplotlib 1.5.1 (anaconda 4.0.5)

Setting the prop_cycle for an axis breaks the usage of keyword aliases in the plot function. In the following snippets the keyword lw=0.1 is ignored, but linewidth=0.1 produces the wanted result.

Maybe it is worth mentioning that color is still accessible via its alias c after setting a prop_cycle.

If it seems weird to set the prop_cycle to just ignore it: I stumbled across this problem while playing around with stylesheets to set a default cycle through different linestyles. But sometimes you want to explicitly change this behaviour.

fig, ax = plt.subplots()
ax.set_prop_cycle('linewidth', [2, 3, 4])
for c in range(5):
    ax.plot(np.arange(10), c * np.arange(10), lw=0.1)

broken

fig, ax = plt.subplots()
ax.set_prop_cycle('linewidth', [2, 3, 4])
for c in range(5):
    ax.plot(np.arange(10), c * np.arange(10), linewidth=0.1)

working

@WeatherGod
Copy link
Member

At first, I was thinking this was a duplicate of #5875 (which is fixed in master), but I see that this is different. The problem here is that ax.plot() probably isn't properly normalizing all of the various keyword arguments, and as such doesn't detect that the cycler and the keyword property are colliding.

The plot() function explicitly normalizes the 'c' keyword into 'color', but it doesn't do it for any other properties. I think I can put together a patch for this utilizing the same normalization tool that the cycler goes through. @tacaswell, wasn't there another normalization mechanism that was added recently?

@tacaswell
Copy link
Member

@tacaswell tacaswell added this to the 1.5.2 (Critical bug fix release) milestone Apr 28, 2016
@WeatherGod
Copy link
Member

but we need to use it places now

Sorry... my parser couldn't grok that sentence.

@tacaswell
Copy link
Member

I mean we have the function available to use, but we need to actually use it in plot, etc

@WeatherGod
Copy link
Member

Ah. Yeah, I started looking into that, and I am not entirely sure it is ready for prime-time. At least, we don't really have the supporting data for it. One of the big problems I see is that it requires me to know what other keyword arguments will be allowed that don't go through the aliasing mechanism.

Perhaps it makes sense to break this function out into three levels. The first level simply does normalization (like I do in the validation step of prop_cycle), and the second level does precedence handling (conflict resolution), and the third level does the "required"/"allowed" handling?

@tacaswell
Copy link
Member

the allowed parameter only does something if it is not None, otherwise it lets things pass through.

@WeatherGod
Copy link
Member

I created #6345 that should address this problem. Note that v1.5.x will still have a problem if your manually created property cycle uses aliased property names, but that is fixed in 2.x as I noted earlier.

@lkluft
Copy link
Author

lkluft commented Apr 30, 2016

This seems to solve the problem properly so I closed the issue.

Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants