Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import numpy as np 

2 

3def rainbow(n): 

4 """ 

5 Returns a list of colors sampled at equal intervals over the spectrum. 

6 

7 Parameters 

8 ---------- 

9 n : int 

10 The number of colors to return 

11 

12 Returns 

13 ------- 

14 R : (n,3) array 

15 An of rows of RGB color values 

16 

17 Notes 

18 ----- 

19 Converts from HSV coordinates (0, 1, 1) to (1, 1, 1) to RGB. Based on 

20 the Sage function of the same name. 

21 """ 

22 from matplotlib import colors 

23 R = np.ones((1,n,3)) 

24 R[0,:,0] = np.linspace(0, 1, n, endpoint=False) 

25 #Note: could iterate and use colorsys.hsv_to_rgb 

26 return colors.hsv_to_rgb(R).squeeze()