kevin-toolbox-dev 1.3.6__py3-none-any.whl → 1.3.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kevin_toolbox/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.3.6"
1
+ __version__ = "1.3.7"
2
2
 
3
3
 
4
4
  import os
@@ -12,5 +12,5 @@ os.system(
12
12
  os.system(
13
13
  f'python {os.path.split(__file__)[0]}/env_info/check_validity_and_uninstall.py '
14
14
  f'--package_name kevin-toolbox-dev '
15
- f'--expiration_timestamp 1735563213 --verbose 0'
15
+ f'--expiration_timestamp 1738073103 --verbose 0'
16
16
  )
@@ -211,6 +211,7 @@ def write(var, output_dir, settings=None, traversal_mode=Traversal_Mode.BFS, b_p
211
211
  file_path=os.path.join(temp_output_dir, "record.json"), b_use_suggested_converter=True)
212
212
 
213
213
  # 打包成 .tar 文件
214
+ for_os.remove(path=tgt_path, ignore_errors=True)
214
215
  if b_pack_into_tar:
215
216
  for_os.pack(source=temp_output_dir)
216
217
  os.rename(temp_output_dir + ".tar", output_dir + ".tar")
@@ -1,4 +1,4 @@
1
1
  from .arrow3d import Arrow3D
2
2
  from .add_trajectory_2d import add_trajectory_2d
3
3
  from .add_trajectory_3d import add_trajectory_3d
4
- from .generate_color_list import generate_color_list
4
+ from .clear_border_of_axes import clear_border_of_axes
@@ -0,0 +1,34 @@
1
+ def clear_border_of_axes(ax):
2
+ """
3
+ 用于清除 ax 中的坐标轴和 ticks
4
+ """
5
+ ax.set_xticks([])
6
+ ax.set_yticks([])
7
+ ax.spines['left'].set_color('none')
8
+ ax.spines['right'].set_color('none')
9
+ ax.spines['bottom'].set_color('none')
10
+ ax.spines['top'].set_color('none')
11
+ return ax
12
+
13
+
14
+ if __name__ == '__main__':
15
+ import matplotlib.pyplot as plt
16
+
17
+ #
18
+ fig, ax = plt.subplots()
19
+
20
+ x = [1, 4]
21
+ y = [1, 10]
22
+ ax.plot(x, y)
23
+
24
+ # 设置坐标轴的范围,以便更好地展示直线
25
+ ax.set_xlim([0, 5])
26
+ ax.set_ylim([0, 15])
27
+
28
+ # 添加标题和坐标轴标签
29
+ ax.set_xlabel('X')
30
+ ax.set_ylabel('Y')
31
+ clear_border_of_axes(ax)
32
+
33
+ # 显示图形
34
+ plt.show()
@@ -0,0 +1,4 @@
1
+ from .color_format import Color_Format
2
+ from .get_format import get_format
3
+ from .convert_format import convert_format
4
+ from .generate_color_list import generate_color_list
@@ -0,0 +1,7 @@
1
+ from enum import Enum
2
+
3
+
4
+ class Color_Format(Enum):
5
+ HEX_STR = "hex_str" # 例如 '#FF573380'
6
+ RGBA_ARRAY = "rgba_array" # 例如 (255, 87, 51, 0.5)
7
+ NATURAL_NAME = "natural_name" # 例如 'red'
@@ -0,0 +1,108 @@
1
+ from kevin_toolbox.patches.for_matplotlib.color import Color_Format, get_format
2
+
3
+
4
+ def hex_to_rgba(hex_color):
5
+ hex_color = hex_color.lstrip('#')
6
+ assert len(hex_color) in (6, 8), \
7
+ f'hex_color should be 6 or 8 characters long (not including #). but got {len(hex_color)}'
8
+ res = list(int(hex_color[i * 2:i * 2 + 2], 16) for i in range(len(hex_color) // 2))
9
+ if len(res) not in (3, 4):
10
+ breakpoint()
11
+ if len(res) == 4:
12
+ res[3] /= 255
13
+ return tuple(res)
14
+
15
+
16
+ def rgba_to_hex(rgba):
17
+ assert len(rgba) in (3, 4), \
18
+ f'rgba should be 3 or 4 elements long. but got {len(rgba)}'
19
+ if len(rgba) == 4:
20
+ rgba = list(rgba)
21
+ rgba[3] = max(0, min(255, int(255 * rgba[3])))
22
+ res = "#"
23
+ for i in rgba:
24
+ res += f'{i:02X}'
25
+ return res
26
+
27
+
28
+ NAME_TO_HEX = {
29
+ 'blue': '#0000FF',
30
+ 'red': '#FF0000',
31
+ 'green': '#008000',
32
+ 'orange': '#FFA500',
33
+ 'purple': '#800080',
34
+ 'yellow': '#FFFF00',
35
+ 'brown': '#A52A2A',
36
+ 'pink': '#FFC0CB',
37
+ 'gray': '#808080',
38
+ 'olive': '#808000',
39
+ 'cyan': '#00FFFF'
40
+ }
41
+ HEX_TO_NAME = {v: k for k, v in NAME_TO_HEX.items()}
42
+
43
+
44
+ def natural_name_to_hex(name):
45
+ global NAME_TO_HEX
46
+ name = name.lower()
47
+ assert name in NAME_TO_HEX, \
48
+ f'{name} is not a valid color name.'
49
+ return NAME_TO_HEX[name]
50
+
51
+
52
+ def hex_to_natural_name(hex_color):
53
+ global HEX_TO_NAME
54
+ hex_color = hex_color.upper()[:7]
55
+ assert hex_color in HEX_TO_NAME, \
56
+ f'{hex_color} does not has corresponding color name.'
57
+ return HEX_TO_NAME[hex_color]
58
+
59
+
60
+ CONVERT_PROCESS_S = {
61
+ (Color_Format.HEX_STR, Color_Format.NATURAL_NAME): hex_to_natural_name, # (from, to): process
62
+ (Color_Format.HEX_STR, Color_Format.RGBA_ARRAY): hex_to_rgba,
63
+ (Color_Format.NATURAL_NAME, Color_Format.HEX_STR): natural_name_to_hex,
64
+ (Color_Format.NATURAL_NAME, Color_Format.RGBA_ARRAY): lambda x: hex_to_rgba(natural_name_to_hex(x)),
65
+ (Color_Format.RGBA_ARRAY, Color_Format.HEX_STR): rgba_to_hex,
66
+ (Color_Format.RGBA_ARRAY, Color_Format.NATURAL_NAME): lambda x: hex_to_natural_name(rgba_to_hex(x))
67
+ }
68
+
69
+
70
+ def convert_format(var, output_format, input_format=None):
71
+ """
72
+ 在各种颜色格式之间进行转换
73
+
74
+ 参数:
75
+ var:
76
+ input_format: <str> 描述输入的格式。
77
+ 支持 HEX_STR、NATURAL_NAME、RGBA_ARRAY 等格式,
78
+ 默认为 None,此时将根据输入推断格式
79
+ output_format: <str/list of str> 输出的目标格式。
80
+ 当输入是一个 tuple/list 时,将输出其中任一格式,具体规则为:
81
+ - 当 input_format 不在可选的输出格式中时,优先按照第一个输出格式进行转换。
82
+ 若转换失败,则按照第二个输出格式进行转换。依次类推。
83
+ - 当 input_format 在可选的输出格式中时,不进行转换。
84
+ """
85
+ global CONVERT_PROCESS_S
86
+ if input_format is None:
87
+ input_format = get_format(var=var)
88
+ input_format = Color_Format(input_format)
89
+ if not isinstance(output_format, (list, tuple,)):
90
+ output_format = [output_format]
91
+ output_format = [Color_Format(i) for i in output_format]
92
+
93
+ if input_format in output_format:
94
+ return var
95
+ else:
96
+ for output_format_i in output_format:
97
+ try:
98
+ return CONVERT_PROCESS_S[(input_format, output_format_i)](var)
99
+ except Exception as e:
100
+ raise Exception(f'fail to convert {var} from {input_format} to {output_format}, beacause: {e}')
101
+
102
+
103
+ if __name__ == '__main__':
104
+ print(hex_to_rgba('#FF57337F'))
105
+ print(rgba_to_hex((255, 87, 51, 0.5)))
106
+ print(natural_name_to_hex('pink'))
107
+ print(convert_format(var='#FF57337F', input_format='hex_str', output_format='rgba_array'))
108
+ print(convert_format(var="#0000FF", output_format="rgba_array"))
@@ -0,0 +1,50 @@
1
+ from kevin_toolbox.patches.for_matplotlib.color import Color_Format, convert_format
2
+ from kevin_toolbox.patches.for_numpy import random
3
+
4
+ PREDEFINED = ['blue', 'red', 'green', 'orange', 'purple', 'yellow', "brown", "pink", "gray", "olive", "cyan"]
5
+ PREDEFINED = [convert_format(var=i, output_format=Color_Format.HEX_STR) for i in PREDEFINED]
6
+
7
+ population = tuple('0123456789ABCDEF')
8
+
9
+
10
+ def generate_color_list(nums, seed=None, rng=None, exclude_ls=None, output_format=Color_Format.HEX_STR):
11
+ """
12
+ 生成颜色列表
13
+
14
+ 参数:
15
+ nums: <int> 生成颜色的数量
16
+ seed,rng: 随机种子或随机生成器,二选一
17
+ exclude: <list of str> 需要排除的颜色
18
+ output_format: <Color_Format/str> 输出格式
19
+ 支持 HEX_STR、RGBA_ARRAY 两种格式
20
+ 返回:
21
+ 不包含 alpha 透明度值的颜色列表
22
+ """
23
+ global PREDEFINED, population
24
+ assert output_format in [Color_Format.HEX_STR, Color_Format.RGBA_ARRAY]
25
+ output_format = Color_Format(output_format)
26
+ if exclude_ls is None:
27
+ exclude_ls = []
28
+ assert isinstance(exclude_ls, (list, tuple))
29
+ exclude_ls = set(convert_format(var=i, output_format=Color_Format.HEX_STR) for i in exclude_ls)
30
+ rng = random.get_rng(seed=seed, rng=rng)
31
+
32
+ colors = [i for i in PREDEFINED if i not in exclude_ls][:nums] # 优先输出预定义的颜色
33
+
34
+ # 随机生成剩余数量的颜色
35
+ while len(colors) < nums:
36
+ c = "#" + ''.join(
37
+ rng.choice(population, size=6, replace=True))
38
+ if c not in colors and c not in exclude_ls:
39
+ colors.append(c)
40
+ colors = [convert_format(c, output_format=output_format) for c in colors]
41
+
42
+ return colors
43
+
44
+
45
+ if __name__ == '__main__':
46
+ color_list = generate_color_list(1, exclude_ls=['blue'])
47
+ print(color_list)
48
+
49
+ color_list = generate_color_list(nums=1, seed=114, exclude_ls=['#0000FF'])
50
+ print(color_list)
@@ -0,0 +1,12 @@
1
+ from kevin_toolbox.patches.for_matplotlib.color import Color_Format
2
+
3
+
4
+ def get_format(var):
5
+ if isinstance(var, str):
6
+ if var.startswith("#"):
7
+ res = Color_Format.HEX_STR
8
+ else:
9
+ res = Color_Format.NATURAL_NAME
10
+ else:
11
+ res = Color_Format.RGBA_ARRAY
12
+ return res
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  import matplotlib.pyplot as plt
3
3
  from kevin_toolbox.patches.for_os.path import replace_illegal_chars
4
- from kevin_toolbox.patches.for_matplotlib import generate_color_list
4
+ from kevin_toolbox.patches.for_matplotlib.color import generate_color_list
5
5
 
6
6
 
7
7
  def plot_lines(data_s, title, x_name, output_dir=None, **kwargs):
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  import matplotlib.pyplot as plt
3
- from kevin_toolbox.patches.for_matplotlib import generate_color_list
3
+ from kevin_toolbox.patches.for_matplotlib.color import generate_color_list
4
4
  from kevin_toolbox.patches.for_os.path import replace_illegal_chars
5
5
 
6
6
 
@@ -2,7 +2,7 @@ import os
2
2
  import pandas as pd
3
3
  import seaborn as sns
4
4
  import matplotlib.pyplot as plt
5
- from kevin_toolbox.patches.for_matplotlib import generate_color_list
5
+ from kevin_toolbox.patches.for_matplotlib.color import generate_color_list
6
6
  from kevin_toolbox.patches.for_os.path import replace_illegal_chars
7
7
 
8
8
 
@@ -24,7 +24,7 @@ def build_study(output_dir=None, feasible_domain_path=None, **kwargs):
24
24
  if "storage" in kwargs:
25
25
  if isinstance(kwargs["storage"], (str,)) and kwargs["storage"].startswith("mysql:"):
26
26
  temp_ls = list(kwargs["storage"].split(":", 1))
27
- temp[0] = "mysql+pymysql"
27
+ temp_ls[0] = "mysql+pymysql"
28
28
  kwargs["storage"] = ":".join(temp_ls)
29
29
  elif isinstance(kwargs["storage"], (dict,)):
30
30
  kwargs["storage"] = build_storage(output_dir=output_dir, **kwargs["storage"]).url
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kevin-toolbox-dev
3
- Version: 1.3.6
3
+ Version: 1.3.7
4
4
  Summary: 一个常用的工具代码包集合
5
5
  Home-page: https://github.com/cantbeblank96/kevin_toolbox
6
6
  Download-URL: https://github.com/username/your-package/archive/refs/tags/v1.0.0.tar.gz
@@ -91,5 +91,13 @@ pip install kevin-toolbox --no-dependencies
91
91
  - 【new feature】modify Average_Accumulator,在 add() 中新增了 weight 参数用于计算带权重的平均值
92
92
  - modify Exponential_Moving_Average,add_sequence() 不再支持 weight_ls 参数,让该接口与其他类更加一致。
93
93
  - 添加了测试用例。
94
+ - v 1.3.7 (2024-08-01)【new feature】
95
+ - patches.for_matplotlib
96
+ - 【new feature】add clear_border_of_axes(),用于清除 ax 中的坐标轴和 ticks。
97
+ - 【new feature】add module color,添加用于处理颜色相关的模块,包含以下函数和属性
98
+ - Color_Format 颜色格式,共有 HEX_STR、RGBA_ARRAY、NATURAL_NAME 三种
99
+ - get_format(),推断所属颜色格式
100
+ - convert_format(),在各种颜色格式之间进行转换
101
+ - generate_color_list(),改进自原来的 for_matplotlib.generate_color_list(),新增了output_format参数用于对颜色格式的控制
94
102
 
95
103
 
@@ -1,4 +1,4 @@
1
- kevin_toolbox/__init__.py,sha256=GlBohqsdsyQwDemVwoyESNeDlLwAoCVkFPWXyasVc5U,410
1
+ kevin_toolbox/__init__.py,sha256=2zesFjPoSdPgShu8x4WbQ8lxiXVZy32fZOBZe50HpPo,410
2
2
  kevin_toolbox/computer_science/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  kevin_toolbox/computer_science/algorithm/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
4
  kevin_toolbox/computer_science/algorithm/cache_manager/__init__.py,sha256=p2hddkZ1HfYF9-m2Hx-o9IotwQHd4QwDCePy2ADpTDA,41
@@ -239,7 +239,7 @@ kevin_toolbox/nested_dict_list/serializer/enum_variable.py,sha256=RWPydtXI4adOJY
239
239
  kevin_toolbox/nested_dict_list/serializer/read.py,sha256=BjsEWYoyvEHgRKKVKw0suf1ukug2tAFLMCAmEnndqgg,2945
240
240
  kevin_toolbox/nested_dict_list/serializer/saved_node_name_builder.py,sha256=qsD-rmDmVaKZP4owN3Wm3QY2Ksi71XlYETqw4VmIsSU,1011
241
241
  kevin_toolbox/nested_dict_list/serializer/variable.py,sha256=ZywG6obipRBCGY1cY42gdvsuWk8GLZXr6eCYcW7ZJ9c,392
242
- kevin_toolbox/nested_dict_list/serializer/write.py,sha256=HCT_vAUqJPQgMrEZKzLzlu1mA2aSZnmGQ1SqNe5X1fI,21845
242
+ kevin_toolbox/nested_dict_list/serializer/write.py,sha256=HDmwEQHTnhFYITItFxM5Zw7sl7F4a50_MN59mR-pU3g,21898
243
243
  kevin_toolbox/nested_dict_list/serializer/backends/__init__.py,sha256=8g7y-L3cmctxao616dVkGiot00FJzKNmNl_69V2bSmE,39
244
244
  kevin_toolbox/nested_dict_list/serializer/backends/_json_.py,sha256=oJXIc28yjxsD9ZJuw120pVHTVsTzCdaXEhVUSQeydq4,2145
245
245
  kevin_toolbox/nested_dict_list/serializer/backends/_ndl.py,sha256=3YkAq_Bqzehnw0kGxqxwtF6uUz0EV37tLI-1ROHjixY,1794
@@ -260,18 +260,23 @@ kevin_toolbox/nested_dict_list/value_parser/replace_identical_with_reference.py,
260
260
  kevin_toolbox/patches/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
261
261
  kevin_toolbox/patches/for_logging/__init__.py,sha256=xymF6mjwY4Cin7CoEwanFY5ZVk8oY0pDLqjZAGa7_Rg,39
262
262
  kevin_toolbox/patches/for_logging/build_logger.py,sha256=0UoRMKaERd8wlHGTiNR3dbLQRAtXcb0QZuGkX2oFgGo,3071
263
- kevin_toolbox/patches/for_matplotlib/__init__.py,sha256=iFN3eCUhKN_QbnAiYSc7dPNLmjhjo7i9D2OdLprEdOw,180
263
+ kevin_toolbox/patches/for_matplotlib/__init__.py,sha256=Pr9jXGomD3wBvtKE8p9V7rKDY4YBLAP5ayWEuBbDdk4,182
264
264
  kevin_toolbox/patches/for_matplotlib/add_trajectory_2d.py,sha256=mKXRUNJiEZBcff3pAkwL_gcKGn55CLRhYCTSd3fj1Go,1837
265
265
  kevin_toolbox/patches/for_matplotlib/add_trajectory_3d.py,sha256=VGlZfVY0xhUBOUzWJVPxZZNHHRvWLR0HZzhADA_cbsU,1696
266
266
  kevin_toolbox/patches/for_matplotlib/arrow3d.py,sha256=JSnNMr1hU2N4FUX526I4MDr04mksDgu4VuegYFDxk1Q,1361
267
- kevin_toolbox/patches/for_matplotlib/generate_color_list.py,sha256=byGZiehbPMUz4DnMtAUbjLL6UADahWEA4vBbaneDPH8,984
267
+ kevin_toolbox/patches/for_matplotlib/clear_border_of_axes.py,sha256=aQtzrw4W-DUffvwTqsA9Ez7b_vj-C58ROE_UcCKIawQ,725
268
+ kevin_toolbox/patches/for_matplotlib/color/__init__.py,sha256=5VGALqLCFsGqBWrOnFouVxkpp_DfqMIcKDLzYPdOTy8,170
269
+ kevin_toolbox/patches/for_matplotlib/color/color_format.py,sha256=ADwKfPmryxOuN691ol_2djOIkGQGJcnUAcqE3pbxGJs,205
270
+ kevin_toolbox/patches/for_matplotlib/color/convert_format.py,sha256=fmFwirEqF2OXuH3qiQD_vCTUBqsqDIDR6F62mIX5XmU,4040
271
+ kevin_toolbox/patches/for_matplotlib/color/generate_color_list.py,sha256=TZm-TkOuJbFzJ0_RklliQ9SHjMUhJvjbu7DUJGtgvw0,1993
272
+ kevin_toolbox/patches/for_matplotlib/color/get_format.py,sha256=l_vX8DUsWHNzLwveuF60TLcbQ_P7PvVt1yH_7FjElDs,312
268
273
  kevin_toolbox/patches/for_matplotlib/common_charts/__init__.py,sha256=etey2r0LO4PTLnH3VzcRKFe7IHP9I5TMW3DEz3sQx2c,270
269
274
  kevin_toolbox/patches/for_matplotlib/common_charts/plot_bars.py,sha256=crS1h79Dz6gGOnqhjuuN2o5pl8CekhCenx9lRz5KPiI,1887
270
275
  kevin_toolbox/patches/for_matplotlib/common_charts/plot_confusion_matrix.py,sha256=dxkgiXeoIdtXzcg_HoUnRGqhJk91iNoB5VbLuoG7o_M,2191
271
276
  kevin_toolbox/patches/for_matplotlib/common_charts/plot_distribution.py,sha256=stuyaULWM_vVW3r9WrpzGqA8rohQrdNKT3Agsbobqck,2396
272
- kevin_toolbox/patches/for_matplotlib/common_charts/plot_lines.py,sha256=qhkshWw9kKF2_acv1h59CwZgJIpJ3eiPTmcEcNyhlQE,1985
273
- kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters.py,sha256=JCCBV9gLJ07b8y57rBb6SawZVhLPqwUXI-UBPyT18h8,1652
274
- kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters_matrix.py,sha256=-ki6h4j-4OHJNCyb2a04l_2uQxUqD2QOMgYfRLmHmVU,1983
277
+ kevin_toolbox/patches/for_matplotlib/common_charts/plot_lines.py,sha256=rb95pupvaiEiGi3o0CP2v-qcOkl1nYF_kgxCTSLGPjI,1991
278
+ kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters.py,sha256=whO36bmixjwtsjCS6Ah6zEGJAlJyGcD-wmV3dA6u7mk,1658
279
+ kevin_toolbox/patches/for_matplotlib/common_charts/plot_scatters_matrix.py,sha256=bf2EfGlPW9dtDfRse1gk8RVxvC8CJ0NeMdrpSw43wFg,1989
275
280
  kevin_toolbox/patches/for_numpy/__init__.py,sha256=SNjZGxTRBn-uzkyZi6Jcz-9juhhZKT8TI70qH-fhGGc,21
276
281
  kevin_toolbox/patches/for_numpy/linalg/__init__.py,sha256=TH-M0Orrakyf9S9A8FiDf3zLHY24gP2SGGTuNmLhDP4,128
277
282
  kevin_toolbox/patches/for_numpy/linalg/cos_similar.py,sha256=bFkfDwrW3maXq5i9ZABidKfg8ZdEdXfFgNzW_uygrM4,423
@@ -286,7 +291,7 @@ kevin_toolbox/patches/for_numpy/random/variable.py,sha256=Sam-QZgkx9_IvHzZhpUrXl
286
291
  kevin_toolbox/patches/for_optuna/__init__.py,sha256=5ZVEXbL6zp6a0rqH2LPsiErZrgpcILWUEtTyK31gzSY,249
287
292
  kevin_toolbox/patches/for_optuna/build_sampler.py,sha256=0gRv2vPLyr71mlnTi2cJ4_SxO8WAyQOGL8DXiY7o2Es,1705
288
293
  kevin_toolbox/patches/for_optuna/build_storage.py,sha256=kGY7fsWroFJ4TQUGy5j_qG5xDuapdB0H5dy2IKSJoYw,3327
289
- kevin_toolbox/patches/for_optuna/build_study.py,sha256=8N0ERvVJxSMRemTzJCeVA6ngkAkXqw8AIFFcvOo27V8,2253
294
+ kevin_toolbox/patches/for_optuna/build_study.py,sha256=nDyG8ifHVmMVc0KylD1lU-iO_BlJ49UZwIRdWVUGp-s,2256
290
295
  kevin_toolbox/patches/for_optuna/copy_study.py,sha256=neBGpGuNhVQB5R5wtHem48A2hqBYOXFU1LxxQDUQQw0,2743
291
296
  kevin_toolbox/patches/for_optuna/sample_from_feasible_domain.py,sha256=-Ckwo2N4vhWr08F7ROLfwLWIx4ERwdwn4Q5Ft2JRm7g,7071
292
297
  kevin_toolbox/patches/for_optuna/serialize/__init__.py,sha256=7WTrwFsW1xnW85zECUQtPTRqVUdPU9V1L8UWrFZyyms,35
@@ -323,7 +328,7 @@ kevin_toolbox/patches/for_torch/math/get_y_at_x.py,sha256=bfoVcasZ_tMdhR_1Me0Jli
323
328
  kevin_toolbox/patches/for_torch/math/my_around.py,sha256=ptpU3ids50gwf663EpHbw7raj9tNrDGBFZ5t_uMNH14,1378
324
329
  kevin_toolbox/patches/for_torch/nn/__init__.py,sha256=aJs3RMqRzQmd8KKDmQW9FxwCqS5yfPqEdg-m0PwlQro,39
325
330
  kevin_toolbox/patches/for_torch/nn/lambda_layer.py,sha256=KUuLiX_Dr4bvRmpAaCW5QTDWDcnMPRnw0jg4NNXTFhM,223
326
- kevin_toolbox_dev-1.3.6.dist-info/METADATA,sha256=c8MZR_BQteWmD6dhfIvq056-O0Ve0Gv4cyPwNn_86t4,4178
327
- kevin_toolbox_dev-1.3.6.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
328
- kevin_toolbox_dev-1.3.6.dist-info/top_level.txt,sha256=S5TeRGF-PwlhsaUEPTI-f2vWrpLmh3axpyI6v-Fi75o,14
329
- kevin_toolbox_dev-1.3.6.dist-info/RECORD,,
331
+ kevin_toolbox_dev-1.3.7.dist-info/METADATA,sha256=7Mr6vujSwCm_da7yVColjXQt7ou4Z-Xm8rlfamc3AJs,4807
332
+ kevin_toolbox_dev-1.3.7.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
333
+ kevin_toolbox_dev-1.3.7.dist-info/top_level.txt,sha256=S5TeRGF-PwlhsaUEPTI-f2vWrpLmh3axpyI6v-Fi75o,14
334
+ kevin_toolbox_dev-1.3.7.dist-info/RECORD,,
@@ -1,33 +0,0 @@
1
- import random
2
-
3
- PREDEFINED = ['blue', 'red', 'green', 'orange', 'purple', 'yellow', "brown", "pink", "gray", "olive", "cyan"]
4
-
5
-
6
- def generate_color_list(nums, seed=None, exclude_ls=None):
7
- """
8
- 参数:
9
- nums: <int> 生成颜色的数量
10
- seed: 随机种子
11
- exclude: <list of str> 需要排除的颜色
12
- """
13
- global PREDEFINED
14
- if exclude_ls is None:
15
- exclude_ls = []
16
- assert isinstance(exclude_ls, (list, tuple))
17
-
18
- colors = [i for i in PREDEFINED if i not in exclude_ls][:nums] # 优先输出预定义的颜色
19
-
20
- # 随机生成剩余数量的颜色
21
- if seed is not None:
22
- random.seed(seed)
23
- while len(colors) < nums:
24
- c = "#" + ''.join(random.choices('0123456789ABCDEF', k=6))
25
- if c not in colors and c not in exclude_ls:
26
- colors.append(c)
27
-
28
- return colors
29
-
30
-
31
- if __name__ == '__main__':
32
- color_list = generate_color_list(20)
33
- print(color_list)