File tree 1 file changed +6
-10
lines changed
pandas/plotting/_matplotlib
1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change
1
+ import itertools
1
2
from typing import (
2
3
TYPE_CHECKING ,
3
4
Collection ,
@@ -74,7 +75,7 @@ def get_standard_colors(
74
75
num_colors = num_colors ,
75
76
)
76
77
77
- return _cycle_colors (colors , num_colors = num_colors )
78
+ return list ( _cycle_colors (colors , num_colors = num_colors ) )
78
79
79
80
80
81
def _derive_colors (
@@ -128,19 +129,14 @@ def _derive_colors(
128
129
return _get_colors_from_color_type (color_type , num_colors = num_colors )
129
130
130
131
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` .
133
134
134
135
Extra colors will be ignored by matplotlib if there are more colors
135
136
than needed and nothing needs to be done here.
136
137
"""
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 )
144
140
145
141
146
142
def _get_colors_from_colormap (
You can’t perform that action at this time.
0 commit comments