File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed
pandas/plotting/_matplotlib Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 1+ import itertools
12from typing import (
23 TYPE_CHECKING ,
34 Collection ,
@@ -74,7 +75,7 @@ def get_standard_colors(
7475 num_colors = num_colors ,
7576 )
7677
77- return _cycle_colors (colors , num_colors = num_colors )
78+ return list ( _cycle_colors (colors , num_colors = num_colors ) )
7879
7980
8081def _derive_colors (
@@ -128,19 +129,14 @@ def _derive_colors(
128129 return _get_colors_from_color_type (color_type , num_colors = num_colors )
129130
130131
131- def _cycle_colors (colors : List [Color ], num_colors : int ) -> List [Color ]:
132- """Append more colors by cycling if there is not enough color .
132+ def _cycle_colors (colors : List [Color ], num_colors : int ) -> Iterator [Color ]:
133+ """Cycle colors until achieving max of `num_colors` or length of `colors` .
133134
134135 Extra colors will be ignored by matplotlib if there are more colors
135136 than needed and nothing needs to be done here.
136137 """
137- if len (colors ) < num_colors :
138- multiple = num_colors // len (colors ) - 1
139- mod = num_colors % len (colors )
140- colors += multiple * colors
141- colors += colors [:mod ]
142-
143- return colors
138+ max_colors = max (num_colors , len (colors ))
139+ yield from itertools .islice (itertools .cycle (colors ), max_colors )
144140
145141
146142def _get_colors_from_colormap (
You can’t perform that action at this time.
0 commit comments