Skip to content

ENH: extra colors generated by get_standard_colors #37604

Closed
@ivanovmg

Description

@ivanovmg

Is your feature request related to a problem?

Not necessarily an issue, but one can get some code improvement and consistency in pandas.plotting._matplotlib.style.get_standard_colors, when it is related to cycling colors.
During refactoring of the module (#37203) it turned out that cycling the colors works in a strange (although tolerable way).

>>> from pandas.plotting._matplotlib.style import get_standard_colors
>>> get_standard_colors(num_colors=2, color='rgb')
'rgb'
>>> get_standard_colors(num_colors=3, color='rgb')
'rgb'
>>> get_standard_colors(num_colors=4, color='rgb')
'rgbr'
>>>

From the snippets above one can see that in the second and third examples work reasonable.
Meanwhile, the first one returns three colors, rather than two.
Extra color(s) will be ignored anyway, but in regards to the discussion in the referenced PR, the way of cycling colors can be improved #37203 (comment)

Describe the solution you'd like

I suggest using matplotlib's cycler (or other generator) to cycle through the colors obtained and get the exact number of colors required, without any extra.
This will simplify the code involving colors cycling in get_standard_colors.

Expected Output

>>> from pandas.plotting._matplotlib.style import get_standard_colors
>>> get_standard_colors(num_colors=2, color='rgb')
'rg'

API breaking implications

Will break some tests related to get_standard_colors only as they expect extra colors to be returned on some occasions.

Describe alternatives you've considered

See #37203 without involving modifications to color cycling.

Metadata

Metadata

Assignees

Labels

EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions