-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcdcplot.py
More file actions
129 lines (109 loc) · 3.23 KB
/
Copy pathcdcplot.py
File metadata and controls
129 lines (109 loc) · 3.23 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'''
Plot helper
functions
'''
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.pyplot import imread
from cycler import cycler
import numpy as np
# colors via Van Gogh
colors = {"cdblue": "#286090",
"brown" :"#7D5D2D",
"green" :"#233A2D",
"tan" :"#C5C88F",
"blue" :"#455778",
"lightblue" :"#9EACC5",
"gold" :"#A58E38",
"cdgrey": "#DDDDDD"}
andy_cycler = cycler(color=list(colors.values()))
#######################################
# seeing available fonts
#from matplotlib import font_manager
#fl = font_manager.findSystemFonts(fontpaths=None, fontext="ttf")
#
#otf = [f for f in fl if f[-3:] == 'otf']
#
#font_manager.findfont("KpSans")
#font_manager.get_font(otf[-1])
#font_manager.findfont("KpSans")
#######################################
andy_theme = {'font.sans-serif': 'Verdana',
'font.family': 'sans-serif',
'axes.grid': True,
'axes.axisbelow': True,
'grid.linestyle': '--',
'grid.color': colors['cdgrey'],
'legend.framealpha': 1,
'legend.facecolor': 'white',
'legend.shadow': True,
'legend.fontsize': 14,
'legend.title_fontsize': 16,
'xtick.labelsize': 14,
'ytick.labelsize': 14,
'axes.labelsize': 16,
'axes.titlesize': 20,
'figure.dpi': 200,
'axes.titlelocation': 'left',
'axes.prop_cycle': andy_cycler}
matplotlib.rcParams.update(andy_theme)
im = imread('WLineRec.PNG')
def add_logo(ax, loc=[0.78,0.78], size=0.2, logo=im):
if loc is None:
return None
if type(logo) == str:
im = image.imread(logo)
else:
im = logo
xrange = ax.get_xlim()
yrange = ax.get_ylim()
xdif = xrange[1] - xrange[0]
ydif = yrange[1] - yrange[0]
startx = loc[0]*xdif + xrange[0]
starty = loc[1]*ydif + yrange[0]
coords = [startx,starty,size*xdif,size*ydif]
axin = ax.inset_axes(coords,transform=ax.transData)
axin.imshow(im)
axin.axis('off')
# combining legend
def combo_legend(ax):
handler, labeler = ax.get_legend_handles_labels()
hd = []
labli = list(set(labeler))
for lab in labli:
comb = [h for h,l in zip(handler,labeler) if l == lab]
hd.append(tuple(comb))
return hd, labli
# check colors
def check_colors():
lc = len(colors)
x = range(lc)
y = [1]*lc
cy = andy_cycler()
fig, ax = plt.subplots()
for a,b in zip(x,y):
b = ax.barh(-a,b,label=a)
t = ax.text(0.5,-a,next(cy)['color'],horizontalalignment='center',
verticalalignment='center')
ax.set_axis_off()
fig.show()
# Brownian motion
def traj(n):
pv = np.random.random() - 0.5
res = [pv]
for i in range(n-1):
nv = pv + np.random.random() - 0.5
res.append(nv)
pv = nv
return res
def check_line(n=20,**kwargs):
lc = len(colors)
x = range(n)
cy = andy_cycler()
y = [traj(n) for _ in range(lc)]
fig, ax = plt.subplots()
for t in y:
l = ax.plot(x,t,'-',markeredgecolor='white',label=next(cy)['color'],**kwargs)
#ax.legend(bbox_to_anchor=(1.0, 0.8))
ax.set_axis_off()
fig.show()