Skip to content

prop_cycle breaks keyword aliases #6343

Closed

Description

@lkluft

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

Activity

  1. WeatherGod commented on Apr 28, 2016

    @WeatherGod
    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?

  2. tacaswell commented on Apr 28, 2016

    @tacaswell
    Member
  3. added this to the milestone on Apr 28, 2016
  4. WeatherGod commented on Apr 28, 2016

    @WeatherGod
    Member

    but we need to use it places now

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

  5. tacaswell commented on Apr 28, 2016

    @tacaswell
    Member

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

  6. WeatherGod commented on Apr 28, 2016

    @WeatherGod
    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?

  7. tacaswell commented on Apr 28, 2016

    @tacaswell
    Member

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

  8. WeatherGod commented on Apr 28, 2016

    @WeatherGod
    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.

  9. lkluft commented on Apr 30, 2016

    @lkluft
    Author

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions