Skip to content
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

[Bug]: Markers with numeric name like CARETLEFT cannot be specified using a cycler #27596

Closed
castilma opened this issue Jan 3, 2024 · 5 comments · Fixed by #27613
Closed
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! status: confirmed bug
Milestone

Comments

@castilma
Copy link

castilma commented Jan 3, 2024

Bug summary

I want to cycle between multiple markerstyles, including those with a numeric value like CARETRIGHT as documented here, but I get an exception if I add one of those.

Code for reproduction

#!/usr/bin/env python3

from cycler import cycler
import matplotlib.pyplot as plt
import matplotlib.markers as mk

cycle = cycler(marker=["+",mk.CARETRIGHT])

t=[0,1]
y=[5,6]

plt.rc('axes', prop_cycle=cycle)
plt.plot(t,y)
plt.show()

Actual outcome

Traceback (most recent call last):
  File "/home/mcd/bugs/bug-cycler.py", line 11, in <module>
    plt.rc('axes', prop_cycle=cycle)
  File "/usr/lib/python3.11/site-packages/matplotlib/pyplot.py", line 670, in rc
    matplotlib.rc(group, **kwargs)
  File "/usr/lib/python3.11/site-packages/matplotlib/__init__.py", line 1062, in rc
    rcParams[key] = v
    ~~~~~~~~^^^^^
  File "/usr/lib/python3.11/site-packages/matplotlib/__init__.py", line 734, in __setitem__
    raise ValueError(f"Key {key}: {ve}") from None
ValueError: Key axes.prop_cycle: Could not convert 5 to str

Expected outcome

A plot using CARETLEFT as marker.

Additional information

This seems like it has to do with the fact, that some markers are referred to by number and not by a string like "+".
I don't know whether the problem is in matplotlib, cycler or the combination of both.

Operating system

Artix Linux

Matplotlib Version

3.8.1

Matplotlib Backend

GTK4Agg

Python version

Python 3.11.6

Jupyter version

No response

Installation

Linux package manager

@WeatherGod
Copy link
Member

WeatherGod commented Jan 3, 2024 via email

@tacaswell
Copy link
Member

More specifically

'marker': validate_stringlist,
needs to be updated to accept the int(/enum) values.

In [13]: plt.rcParams['lines.marker'] = mk.CARETRIGHT
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 1
----> 1 plt.rcParams['lines.marker'] = mk.CARETRIGHT

File /usr/lib/python3.11/site-packages/matplotlib/__init__.py:734, in RcParams.__setitem__(self, key, val)
    732         cval = self.validate[key](val)
    733     except ValueError as ve:
--> 734         raise ValueError(f"Key {key}: {ve}") from None
    735     self._set(key, cval)
    736 except KeyError as err:

ValueError: Key lines.marker: Could not convert 5 to str

is a simpler way exercise the same issue.

@tacaswell tacaswell added this to the v3.8.3 milestone Jan 3, 2024
@tacaswell tacaswell added status: confirmed bug Good first issue Open a pull request against these issues if there are no active ones! Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues labels Jan 3, 2024
Copy link

github-actions bot commented Jan 3, 2024

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.

We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication channels.

@tacaswell
Copy link
Member

Steps:

  • update the marker validator to accept all valid marker specifications (atleast the integers, maybe the path and Marker classes as well)
  • add a test
  • add a whats new (if extended past integers)

Good first issue because this is very narrowly scoped, but medium because there is some meta-programming in the validator code. Some thought will need to be given to writing a validator that works for both "live" objects and for strings coming from reading and .matplotlibrc.

@WeatherGod
Copy link
Member

WeatherGod commented Jan 3, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! status: confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants