Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07039a6

Browse files
authored
CLN: Use newer numpy random Generator methods in plotting colors (#61332)
1 parentcf6de58 commit07039a6

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

‎pandas/plotting/_matplotlib/style.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
frompandas.core.dtypes.commonimportis_list_like
2424

25-
importpandas.core.commonascom
26-
2725
ifTYPE_CHECKING:
2826
frommatplotlib.colorsimportColormap
2927

@@ -251,31 +249,17 @@ def _is_floats_color(color: Color | Collection[Color]) -> bool:
251249
def_get_colors_from_color_type(color_type:str,num_colors:int)->list[Color]:
252250
"""Get colors from user input color type."""
253251
ifcolor_type=="default":
254-
return_get_default_colors(num_colors)
252+
prop_cycle=mpl.rcParams["axes.prop_cycle"]
253+
return [
254+
c["color"]
255+
forcinitertools.islice(prop_cycle,min(num_colors,len(prop_cycle)))
256+
]
255257
elifcolor_type=="random":
256-
return_get_random_colors(num_colors)
258+
returnnp.random.default_rng(num_colors).random((num_colors,3)).tolist()
257259
else:
258260
raiseValueError("color_type must be either 'default' or 'random'")
259261

260262

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"]forcinmpl.rcParams["axes.prop_cycle"]]
264-
returncolors[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)fornuminrange(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-
returnrs.rand(3).tolist()
277-
278-
279263
def_is_single_string_color(color:Color)->bool:
280264
"""Check if `color` is a single string color.
281265

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp