Skip to content

Manual linestyle specification ignored if 'prop_cycle' contains 'ls' #5875

Closed

Description

@Chroxvi

If the axes.prop_cycle contains the label 'ls' it is not possible to manually specify a linestyle in a plot. However, if axes.prop_cycle contains the label 'linestyle', everything seems to work as expected.

An example showing the problem:

from cycler import cycler
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.__version__  # ==1.5.1

linestyle_cycle = cycler('linestyle', ['-', '--'])
ls_cycle = cycler('ls', ['-', '--'])

x = np.arange(10)

mpl.rcParams['axes.prop_cycle'] = linestyle_cycle
plt.figure()
for k in range(1, 6):
    plt.plot(x, k * x)
plt.plot(x, x**2, 'k:')  # Black dotted as expected
plt.title('linestyle_cycle')

mpl.rcParams['axes.prop_cycle'] = ls_cycle
plt.figure()
for k in range(1, 6):
    plt.plot(x, k * x)
plt.plot(x, x**2, 'k:')  # Black dashed - not expected
plt.title('ls_cycle')

linestyle_cycle
ls_cycle

Activity

  1. added this to the milestone on Jan 18, 2016
  2. tacaswell commented on Jan 18, 2016

    @tacaswell
    Member

    Thanks for reporting this.

  3. WeatherGod commented on Jan 27, 2016

    @WeatherGod
    Member

    This might be the normalization bug we are seeing elsewhere. I have code
    that normalizes the key names from 'ls' to 'linestyle', but it seems to
    only trigger for cycles defined from the rc file. If a cycle object is
    passed in, it just uses it as-is. Unfortunately, I needed that
    normalization feature to simplify the cycle advancing feature. The
    linestyle given by 'k:' is compared with the properties from the cycler.
    Only properties from the cycler that doesn't exist in the manual
    specification are taken. Unfortunately, without normalization, it sees "ls"
    from the cycler, and "linestyle" from the manual spec and doesn't know that
    they are the same thing. The "ls" value then overrides the "linestyle"
    value when setting the artist properties.

    On Mon, Jan 18, 2016 at 1:40 PM, Thomas A Caswell notifications@github.com
    wrote:

    Thanks for reporting this.

    —
    Reply to this email directly or view it on GitHub
    #5875 (comment)
    .

  4. WeatherGod commented on Jan 27, 2016

    @WeatherGod
    Member

    @tacaswell, we probably need to set a minimum version of cycler to depend
    on so that I can write a patch that utilizes the "key_change()" feature I
    added to cycler awhile back. Have you released a version with that feature?

    On Wed, Jan 27, 2016 at 5:32 PM, Benjamin Root ben.v.root@gmail.com wrote:

    This might be the normalization bug we are seeing elsewhere. I have code
    that normalizes the key names from 'ls' to 'linestyle', but it seems to
    only trigger for cycles defined from the rc file. If a cycle object is
    passed in, it just uses it as-is. Unfortunately, I needed that
    normalization feature to simplify the cycle advancing feature. The
    linestyle given by 'k:' is compared with the properties from the cycler.
    Only properties from the cycler that doesn't exist in the manual
    specification are taken. Unfortunately, without normalization, it sees "ls"
    from the cycler, and "linestyle" from the manual spec and doesn't know that
    they are the same thing. The "ls" value then overrides the "linestyle"
    value when setting the artist properties.

    On Mon, Jan 18, 2016 at 1:40 PM, Thomas A Caswell <
    notifications@github.com> wrote:

    Thanks for reporting this.

    —
    Reply to this email directly or view it on GitHub
    #5875 (comment)
    .

  5. tacaswell commented on Jan 27, 2016

    @tacaswell
    Member

    No, we need to do new release of cycler.

    On Wed, Jan 27, 2016 at 5:39 PM Benjamin Root notifications@github.com
    wrote:

    @tacaswell, we probably need to set a minimum version of cycler to depend
    on so that I can write a patch that utilizes the "key_change()" feature I
    added to cycler awhile back. Have you released a version with that feature?

    On Wed, Jan 27, 2016 at 5:32 PM, Benjamin Root ben.v.root@gmail.com
    wrote:

    This might be the normalization bug we are seeing elsewhere. I have code
    that normalizes the key names from 'ls' to 'linestyle', but it seems to
    only trigger for cycles defined from the rc file. If a cycle object is
    passed in, it just uses it as-is. Unfortunately, I needed that
    normalization feature to simplify the cycle advancing feature. The
    linestyle given by 'k:' is compared with the properties from the cycler.
    Only properties from the cycler that doesn't exist in the manual
    specification are taken. Unfortunately, without normalization, it sees
    "ls"
    from the cycler, and "linestyle" from the manual spec and doesn't know
    that
    they are the same thing. The "ls" value then overrides the "linestyle"
    value when setting the artist properties.

    On Mon, Jan 18, 2016 at 1:40 PM, Thomas A Caswell <
    notifications@github.com> wrote:

    Thanks for reporting this.

    —
    Reply to this email directly or view it on GitHub
    <
    #5875 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    #5875 (comment)
    .

  6. WeatherGod commented on Jan 27, 2016

    @WeatherGod
    Member

    Might also be worth considering monkey-patching cycler if it is missing the
    change_key() method. I think all the relevant logic is contained within
    that method, I'll have to double-check that PR.

    On Wed, Jan 27, 2016 at 5:46 PM, Thomas A Caswell notifications@github.com
    wrote:

    No, we need to do new release of cycler.

    On Wed, Jan 27, 2016 at 5:39 PM Benjamin Root notifications@github.com
    wrote:

    @tacaswell, we probably need to set a minimum version of cycler to depend
    on so that I can write a patch that utilizes the "key_change()" feature I
    added to cycler awhile back. Have you released a version with that
    feature?

    On Wed, Jan 27, 2016 at 5:32 PM, Benjamin Root ben.v.root@gmail.com
    wrote:

    This might be the normalization bug we are seeing elsewhere. I have
    code
    that normalizes the key names from 'ls' to 'linestyle', but it seems to
    only trigger for cycles defined from the rc file. If a cycle object is
    passed in, it just uses it as-is. Unfortunately, I needed that
    normalization feature to simplify the cycle advancing feature. The
    linestyle given by 'k:' is compared with the properties from the
    cycler.
    Only properties from the cycler that doesn't exist in the manual
    specification are taken. Unfortunately, without normalization, it sees
    "ls"
    from the cycler, and "linestyle" from the manual spec and doesn't know
    that
    they are the same thing. The "ls" value then overrides the "linestyle"
    value when setting the artist properties.

    On Mon, Jan 18, 2016 at 1:40 PM, Thomas A Caswell <
    notifications@github.com> wrote:

    Thanks for reporting this.

    —
    Reply to this email directly or view it on GitHub
    <

    #5875 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    <
    #5875 (comment)

    .

    —
    Reply to this email directly or view it on GitHub
    #5875 (comment)
    .

  7. added 2 commits that reference this issue on Apr 6, 2016
    494531e
    bfe5e3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions