|
22 | 22 |
|
23 | 23 | from pandas.core.dtypes.common import is_list_like |
24 | 24 |
|
25 | | -import pandas.core.common as com |
26 | | - |
27 | 25 | if TYPE_CHECKING: |
28 | 26 | from matplotlib.colors import Colormap |
29 | 27 |
|
@@ -251,31 +249,17 @@ def _is_floats_color(color: Color | Collection[Color]) -> bool: |
251 | 249 | def _get_colors_from_color_type(color_type: str, num_colors: int) -> list[Color]: |
252 | 250 | """Get colors from user input color type.""" |
253 | 251 | if color_type == "default": |
254 | | - return _get_default_colors(num_colors) |
| 252 | + prop_cycle = mpl.rcParams["axes.prop_cycle"] |
| 253 | + return [ |
| 254 | + c["color"] |
| 255 | + for c in itertools.islice(prop_cycle, min(num_colors, len(prop_cycle))) |
| 256 | + ] |
255 | 257 | elif color_type == "random": |
256 | | - return _get_random_colors(num_colors) |
| 258 | + return np.random.default_rng(num_colors).random((num_colors, 3)).tolist() |
257 | 259 | else: |
258 | 260 | raise ValueError("color_type must be either 'default' or 'random'") |
259 | 261 |
|
260 | 262 |
|
261 | | -def _get_default_colors(num_colors: int) -> list[Color]: |
262 | | - """Get `num_colors` of default colors from matplotlib rc params.""" |
263 | | - colors = [c["color"] for c in mpl.rcParams["axes.prop_cycle"]] |
264 | | - return colors[0:num_colors] |
265 | | - |
266 | | - |
267 | | -def _get_random_colors(num_colors: int) -> list[Color]: |
268 | | - """Get `num_colors` of random colors.""" |
269 | | - return [_random_color(num) for num in range(num_colors)] |
270 | | - |
271 | | - |
272 | | -def _random_color(column: int) -> list[float]: |
273 | | - """Get a random color represented as a list of length 3""" |
274 | | - # GH17525 use common._random_state to avoid resetting the seed |
275 | | - rs = com.random_state(column) |
276 | | - return rs.rand(3).tolist() |
277 | | - |
278 | | - |
279 | 263 | def _is_single_string_color(color: Color) -> bool: |
280 | 264 | """Check if `color` is a single string color. |
281 | 265 |
|
|
0 commit comments