Skip to content

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

Closed

Description

@castilma

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

Activity

  1. WeatherGod commented on Jan 3, 2024

    @WeatherGod
    Member
  2. tacaswell commented on Jan 3, 2024

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

  3. added this to the v3.8.3 milestone on Jan 3, 2024
  4. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Jan 3, 2024
  5. github-actions commented on Jan 3, 2024

    @github-actions

    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.

  6. tacaswell commented on Jan 3, 2024

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

  7. WeatherGod commented on Jan 3, 2024

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

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesstatus: confirmed bug🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions