Skip to content

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

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
Chroxvi opened this issue Jan 18, 2016 · 5 comments
Closed

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

Chroxvi opened this issue Jan 18, 2016 · 5 comments
Milestone

Comments

@Chroxvi
Copy link

Chroxvi commented Jan 18, 2016

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

@tacaswell tacaswell added this to the Critical bug fix release (1.5.2) milestone Jan 18, 2016
@tacaswell
Copy link
Member

Thanks for reporting this.

@WeatherGod
Copy link
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)
.

@WeatherGod
Copy link
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)
.

@tacaswell
Copy link
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)
.

@WeatherGod
Copy link
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)
.

WeatherGod added a commit to WeatherGod/matplotlib that referenced this issue Apr 6, 2016
* Allow key normalization to Cycler objects
* Validation is performed at more entry points
* Requires Cycler v0.9+
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

3 participants