Skip to content

Commit 1a850c2

Browse files
committed
fix: adding random colour generator
1 parent 464934b commit 1a850c2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

LoopStructural/utils/colours.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from LoopStructural.utils import rng
2+
3+
4+
def random_colour(n: int, cmap='tab20'):
5+
"""
6+
Generate a list of random colours
7+
8+
Parameters
9+
----------
10+
n : int
11+
Number of colours to generate
12+
cmap : str, optional
13+
Name of the matplotlib colour map to use, by default 'tab20'
14+
15+
Returns
16+
-------
17+
list
18+
List of colours in the form of (r,g,b,a) tuples
19+
"""
20+
import matplotlib.cm as cm
21+
22+
colours = []
23+
for _i in range(n):
24+
colours.append(cm.get_cmap(cmap)(rng.random()))
25+
26+
return colours

0 commit comments

Comments
 (0)