-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcb_cyclic.py
97 lines (62 loc) · 1.9 KB
/
cb_cyclic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# ---------------------------- #
# - Author : Clement Fontana - #
# ---------------------------- #
# No licence, free of use
# Load modules
# ------------
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
# Load color map
# -------------
cmap_name = matplotlib.cm.hsv
#cmap_name = matplotlib.cm.twilight
rgb=[]
for i in range(0,cmap_name.N):
rgb.append(cmap_name(i))
rgb=np.array(rgb)
cmap=ListedColormap(rgb)
# Make color bar
# --------------
fig = plt.figure()
ax = plt.subplot(111, polar=True)
N = 480 # Number of lines to draw color bar ( 480 / 960 ...)
Ntick = 12 # Number of ticks ( 6 / 12 / 24 / 48 ...)
ymin = 0.75 # Lower boundary of cb < ymax
ymax = 0.95 # Upper boundary of cb < 1
tick_size = 0.03 # Ticks size
# Define angles
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
# Plot colored lines
for i in range(0,N):
col=cmap( i/N )
plt.plot([theta[i],theta[i]],[ymin,ymax],color=col,linestyle='-',zorder=0)
# ^^^^^ to improve => use bar to manage alpha value
# Plot frame
fmin=np.ones(N)*ymin # Lower frame
fmax=np.ones(N)*ymax # Upper frame
plt.plot(theta,fmin,color='k',linewidth=1,linestyle='-',zorder=0)
plt.plot(theta,fmax,color='k',linewidth=1,linestyle='-',zorder=0)
# Plot ticks
ticks=[]
for i in np.arange(0, N, int(N/Ntick)) :
plt.plot([theta[i],theta[i]],[ymax-tick_size,ymax],'k-')
plt.plot([theta[i],theta[i]],[ymin,ymin+tick_size],'k-')
ticks.append( 2*np.pi*i/N )
ax.xaxis.set_ticks(ticks)
# Tick labels
xlabels=range(0,Ntick)
xlabels=np.char.add('Tick ',np.array(xlabels,dtype=str))
ax.xaxis.set_ticklabels(xlabels)
# Plot parameters
pstr='Ntick = '+str(Ntick)+" | ymin = "+str(ymin)+' | ymax = '+str(ymax)+' | tick_size = '+str(tick_size)
plt.title(pstr)
# Tune
plt.yticks([])
plt.ylim([0,1])
plt.box(on=None)
ax.grid(False)
# Plot
plt.show()
plt.close()