py2ls 0.1.6.0__py3-none-any.whl → 0.1.6.2__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.
- py2ls/.DS_Store +0 -0
- py2ls/.git/logs/refs/remotes/origin/HEAD +12 -0
- py2ls/ips.py +38 -5
- py2ls/plot/catplot.py +437 -0
- py2ls/plot/figsets.py +372 -0
- py2ls/plot/get_color.py +68 -0
- py2ls/plot/stdshade.py +227 -0
- {py2ls-0.1.6.0.dist-info → py2ls-0.1.6.2.dist-info}/METADATA +1 -1
- {py2ls-0.1.6.0.dist-info → py2ls-0.1.6.2.dist-info}/RECORD +10 -7
- {py2ls-0.1.6.0.dist-info → py2ls-0.1.6.2.dist-info}/WHEEL +1 -1
- py2ls/plot.py +0 -665
py2ls/.DS_Store
CHANGED
Binary file
|
@@ -123,3 +123,15 @@ a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be1
|
|
123
123
|
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721298434 +0200 remote set-head
|
124
124
|
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721300398 +0200 remote set-head
|
125
125
|
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721302501 +0200 remote set-head
|
126
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721304466 +0200 remote set-head
|
127
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721306430 +0200 remote set-head
|
128
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721308395 +0200 remote set-head
|
129
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721310359 +0200 remote set-head
|
130
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721312323 +0200 remote set-head
|
131
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721314287 +0200 remote set-head
|
132
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721316252 +0200 remote set-head
|
133
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721318216 +0200 remote set-head
|
134
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721320179 +0200 remote set-head
|
135
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721322143 +0200 remote set-head
|
136
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721324108 +0200 remote set-head
|
137
|
+
a15389729850729fc7bd78a54f26fce77f30be12 a15389729850729fc7bd78a54f26fce77f30be12 Jianfeng Liu <macjianfeng@JFLMBP.cin.medizin.uni-tuebingen.de> 1721326072 +0200 remote set-head
|
py2ls/ips.py
CHANGED
@@ -879,8 +879,9 @@ def fload(fpath, kind=None, **kwargs):
|
|
879
879
|
root = tree.getroot()
|
880
880
|
return etree.tostring(root, pretty_print=True).decode()
|
881
881
|
|
882
|
-
def load_csv(fpath,
|
883
|
-
|
882
|
+
def load_csv(fpath, engine='pyarrow',**kwargs):
|
883
|
+
print(f"engine={engine}")
|
884
|
+
df = pd.read_csv(fpath, engine=engine, **kwargs)
|
884
885
|
return df
|
885
886
|
|
886
887
|
def load_xlsx(fpath, **kwargs):
|
@@ -2043,7 +2044,17 @@ def figsets(*args,**kwargs):
|
|
2043
2044
|
box=['right','bottom'],
|
2044
2045
|
xrot=-45,
|
2045
2046
|
yangle=20,
|
2046
|
-
font_sz = 2
|
2047
|
+
font_sz = 2,
|
2048
|
+
legend=dict(labels=['group_a','group_b'],
|
2049
|
+
loc='upper left',
|
2050
|
+
edgecolor='k',
|
2051
|
+
facecolor='r',
|
2052
|
+
title='title',
|
2053
|
+
fancybox=1,
|
2054
|
+
shadow=1,
|
2055
|
+
ncols=4,
|
2056
|
+
bbox_to_anchor=[-0.5,0.7],
|
2057
|
+
alignment='left')
|
2047
2058
|
)
|
2048
2059
|
"""
|
2049
2060
|
fig = plt.gcf()
|
@@ -2107,6 +2118,10 @@ def figsets(*args,**kwargs):
|
|
2107
2118
|
"tic" not in key.lower() and "tk" not in key.lower()
|
2108
2119
|
):
|
2109
2120
|
ax.set_zlabel(value, fontname=fontname)
|
2121
|
+
if key=='xlabel' and isinstance(value,dict):
|
2122
|
+
ax.set_xlabel(**value)
|
2123
|
+
if key=='ylabel' and isinstance(value,dict):
|
2124
|
+
ax.set_ylabel(**value)
|
2110
2125
|
# tick location
|
2111
2126
|
if "tic" in key.lower() or "tk" in key.lower():
|
2112
2127
|
if ("loc" in key.lower()) or ("po" in key.lower()):
|
@@ -2155,9 +2170,22 @@ def figsets(*args,**kwargs):
|
|
2155
2170
|
# rotation
|
2156
2171
|
if "angle" in key.lower() or ("rot" in key.lower()):
|
2157
2172
|
if "x" in key.lower():
|
2158
|
-
|
2173
|
+
if value in [0,90,180,270]:
|
2174
|
+
ax.tick_params(axis="x", rotation=value)
|
2175
|
+
for tick in ax.get_xticklabels():
|
2176
|
+
tick.set_horizontalalignment('center')
|
2177
|
+
elif value >0:
|
2178
|
+
ax.tick_params(axis="x", rotation=value)
|
2179
|
+
for tick in ax.get_xticklabels():
|
2180
|
+
tick.set_horizontalalignment('right')
|
2181
|
+
elif value <0:
|
2182
|
+
ax.tick_params(axis='x', rotation=value)
|
2183
|
+
for tick in ax.get_xticklabels():
|
2184
|
+
tick.set_horizontalalignment('left')
|
2159
2185
|
if "y" in key.lower():
|
2160
2186
|
ax.tick_params(axis="y", rotation=value)
|
2187
|
+
for tick in ax.get_yticklabels():
|
2188
|
+
tick.set_horizontalalignment('right')
|
2161
2189
|
|
2162
2190
|
if "bo" in key in key: # box setting, and ("p" in key or "l" in key):
|
2163
2191
|
if isinstance(value, (str, list)):
|
@@ -2278,7 +2306,12 @@ def figsets(*args,**kwargs):
|
|
2278
2306
|
if "c" in key.lower() and ("sp" in key.lower() or "ax" in key.lower()):# spine color
|
2279
2307
|
for loc, spi in ax.spines.items():
|
2280
2308
|
spi.set_color(value)
|
2281
|
-
|
2309
|
+
if 'leg' in key.lower(): # legend
|
2310
|
+
legend_kws = kwargs.get('legend', None)
|
2311
|
+
if legend_kws:
|
2312
|
+
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
|
2313
|
+
ax.legend(**legend_kws)
|
2314
|
+
|
2282
2315
|
for arg in args:
|
2283
2316
|
if isinstance(arg,matplotlib.axes._axes.Axes):
|
2284
2317
|
ax=arg
|
py2ls/plot/catplot.py
ADDED
@@ -0,0 +1,437 @@
|
|
1
|
+
import matplotlib.pyplot as plt
|
2
|
+
import numpy as np
|
3
|
+
from matplotlib.colors import to_rgba
|
4
|
+
from scipy.stats import gaussian_kde
|
5
|
+
|
6
|
+
def catplot(data, *args, **kwargs):
|
7
|
+
"""
|
8
|
+
catplot(data, opt=None, ax=None)
|
9
|
+
|
10
|
+
Args:
|
11
|
+
data (array): data matrix
|
12
|
+
"""
|
13
|
+
def plot_bars(data_m, opt_b, xloc, ax):
|
14
|
+
bar_positions = get_positions(xloc, opt_b['loc'], opt_b['x_width'], data.shape[0])
|
15
|
+
bar_positions=np.nanmean(bar_positions,axis=0)
|
16
|
+
for i, (x, y) in enumerate(zip(bar_positions, data_m)):
|
17
|
+
color = to_rgba(opt_b['FaceColor'][i % len(opt_b['FaceColor'])])
|
18
|
+
ax.bar(x, y,
|
19
|
+
width=opt_b['x_width'],
|
20
|
+
color=color,
|
21
|
+
edgecolor=opt_b['EdgeColor'],
|
22
|
+
alpha=opt_b['FaceAlpha'])
|
23
|
+
|
24
|
+
def plot_errors(data, data_m, opt_e, xloc, ax):
|
25
|
+
error_positions = get_positions(xloc, opt_e['loc'], opt_e['x_width'], data.shape[0])
|
26
|
+
error_positions=np.nanmean(error_positions,axis=0)
|
27
|
+
errors = np.nanstd(data, axis=0)
|
28
|
+
if opt_e['error'] == 'sem':
|
29
|
+
errors /= np.sqrt(np.sum(~np.isnan(data),axis=0))
|
30
|
+
|
31
|
+
if not isinstance(opt_e['FaceColor'],list):
|
32
|
+
opt_e['FaceColor']=[opt_e['FaceColor']]
|
33
|
+
if not isinstance(opt_e['MarkerEdgeColor'],list):
|
34
|
+
opt_e['MarkerEdgeColor']=[opt_e['MarkerEdgeColor']]
|
35
|
+
for i, (x, y, err) in enumerate(zip(error_positions, data_m, errors)):
|
36
|
+
ax.errorbar(x, y, yerr=err,
|
37
|
+
fmt=opt_e['Marker'],
|
38
|
+
ecolor=opt_e['LineColor'],
|
39
|
+
elinewidth=opt_e['LineWidth'],
|
40
|
+
lw=opt_e['LineWidth'],
|
41
|
+
ls=opt_e['LineStyle'],
|
42
|
+
capsize=opt_e['CapSize'],
|
43
|
+
capthick=opt_e['CapLineWidth'],
|
44
|
+
markersize=opt_e['MarkerSize'],
|
45
|
+
mec=opt_e['MarkerEdgeColor'][i % len(opt_e['MarkerEdgeColor'])],
|
46
|
+
mfc=opt_e['FaceColor'][i % len(opt_e['FaceColor'])],
|
47
|
+
visible=opt_e['Visible']
|
48
|
+
)
|
49
|
+
|
50
|
+
def plot_scatter(data, opt_s, xloc, ax):
|
51
|
+
scatter_positions = get_positions(xloc, opt_s['loc'], opt_s['x_width'], data.shape[0])
|
52
|
+
for i, (x, y) in enumerate(zip(scatter_positions.T, data.T)):
|
53
|
+
color = to_rgba(opt_s['FaceColor'][i % len(opt_s['FaceColor'])])
|
54
|
+
ax.scatter(x, y,
|
55
|
+
color=color,
|
56
|
+
alpha=opt_s['FaceAlpha'],
|
57
|
+
edgecolor=opt_s['MarkerEdgeColor'],
|
58
|
+
s=opt_s['MarkerSize'],
|
59
|
+
marker=opt_s['Marker']
|
60
|
+
)
|
61
|
+
|
62
|
+
def plot_boxplot(data, bx_opt, xloc,ax):
|
63
|
+
if 'l' in bx_opt['loc']:
|
64
|
+
X_bx = xloc - bx_opt['x_width']
|
65
|
+
elif 'r' in bx_opt['loc']:
|
66
|
+
X_bx = xloc + bx_opt['x_width']
|
67
|
+
elif 'i' in bx_opt['loc']:
|
68
|
+
X_bx = xloc
|
69
|
+
X_bx[:, 0] += bx_opt['x_width']
|
70
|
+
X_bx[:, -1] -= bx_opt['x_width']
|
71
|
+
elif 'o' in bx_opt['loc']:
|
72
|
+
X_bx = xloc
|
73
|
+
X_bx[:, 0] -= bx_opt['x_width']
|
74
|
+
X_bx[:, -1] += bx_opt['x_width']
|
75
|
+
elif 'c' in bx_opt['loc'] or 'm' in bx_opt['loc']:
|
76
|
+
X_bx = xloc
|
77
|
+
else:
|
78
|
+
X_bx = xloc
|
79
|
+
|
80
|
+
|
81
|
+
boxprops = dict(color=bx_opt['EdgeColor'],
|
82
|
+
linewidth=bx_opt['BoxLineWidth'])
|
83
|
+
flierprops = dict(marker=bx_opt['OutlierMarker'],
|
84
|
+
markerfacecolor=bx_opt['OutlierColor'],
|
85
|
+
markersize=bx_opt['OutlierSize'])
|
86
|
+
whiskerprops = dict(linestyle=bx_opt['WhiskerLineStyle'],
|
87
|
+
color=bx_opt['WhiskerLineColor'],
|
88
|
+
linewidth=bx_opt['WhiskerLineWidth'])
|
89
|
+
capprops = dict(color=bx_opt['CapLineColor'],
|
90
|
+
linewidth=bx_opt['CapLineWidth'],)
|
91
|
+
medianprops = dict(linestyle=bx_opt['MedianLineStyle'],
|
92
|
+
color=bx_opt['MedianLineColor'],
|
93
|
+
linewidth=bx_opt['MedianLineWidth'])
|
94
|
+
meanprops = dict(linestyle=bx_opt['MeanLineStyle'],
|
95
|
+
color=bx_opt['MeanLineColor'],
|
96
|
+
linewidth=bx_opt['MeanLineWidth'])
|
97
|
+
bxp = ax.boxplot(data,
|
98
|
+
positions=X_bx,
|
99
|
+
notch=bx_opt['Notch'],
|
100
|
+
patch_artist=True,
|
101
|
+
boxprops=boxprops,
|
102
|
+
flierprops=flierprops,
|
103
|
+
whiskerprops=whiskerprops,
|
104
|
+
capwidths=bx_opt['CapSize'],
|
105
|
+
showfliers = bx_opt['Outliers'],
|
106
|
+
showcaps = bx_opt['Caps'],
|
107
|
+
capprops=capprops,
|
108
|
+
medianprops=medianprops,
|
109
|
+
meanline=bx_opt['MeanLine'],
|
110
|
+
showmeans=bx_opt['MeanLine'],
|
111
|
+
meanprops =meanprops,
|
112
|
+
widths=bx_opt['x_width'])
|
113
|
+
|
114
|
+
if bx_opt['BoxLineWidth'] < 0.1:
|
115
|
+
bx_opt['EdgeColor'] = 'none'
|
116
|
+
else:
|
117
|
+
bx_opt['EdgeColor'] = bx_opt['EdgeColor']
|
118
|
+
|
119
|
+
for patch, color in zip(bxp['boxes'], bx_opt['FaceColor']):
|
120
|
+
patch.set_facecolor(to_rgba(color, bx_opt['FaceAlpha']))
|
121
|
+
|
122
|
+
if bx_opt['MedianLineTop']:
|
123
|
+
ax.set_children(ax.get_children()[::-1]) # move median line forward
|
124
|
+
|
125
|
+
def plot_violin(data, opt_v, xloc, ax):
|
126
|
+
violin_positions = get_positions(xloc, opt_v['loc'], opt_v['x_width'], data.shape[0])
|
127
|
+
violin_positions = np.nanmean(violin_positions, axis=0)
|
128
|
+
for i, (x, ys) in enumerate(zip(violin_positions, data.T)):
|
129
|
+
ys = ys[~np.isnan(ys)]
|
130
|
+
if len(ys) > 1:
|
131
|
+
kde = gaussian_kde(ys, bw_method=opt_v['BandWidth'])
|
132
|
+
min_val, max_val = ys.min(), ys.max()
|
133
|
+
y_vals = np.linspace(min_val, max_val, opt_v['NumPoints'])
|
134
|
+
kde_vals = kde(y_vals)
|
135
|
+
kde_vals = kde_vals / kde_vals.max() * opt_v['x_width']
|
136
|
+
if 'r' in opt_v['loc'].lower():
|
137
|
+
ax.fill_betweenx(y_vals, x, x + kde_vals,
|
138
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
139
|
+
alpha=opt_v['FaceAlpha'],
|
140
|
+
edgecolor=opt_v['EdgeColor'])
|
141
|
+
elif 'l' in opt_v['loc'].lower() and not 'f' in opt_v['loc'].lower() :
|
142
|
+
ax.fill_betweenx(y_vals, x - kde_vals, x,
|
143
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
144
|
+
alpha=opt_v['FaceAlpha'],
|
145
|
+
edgecolor=opt_v['EdgeColor'])
|
146
|
+
elif 'o' in opt_v['loc'].lower() or 'both' in opt_v['loc'].lower() :
|
147
|
+
ax.fill_betweenx(y_vals, x - kde_vals, x + kde_vals,
|
148
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
149
|
+
alpha=opt_v['FaceAlpha'],
|
150
|
+
edgecolor=opt_v['EdgeColor'])
|
151
|
+
elif 'i' in opt_v['loc'].lower():
|
152
|
+
if i % 2 == 1: # odd number
|
153
|
+
ax.fill_betweenx(y_vals, x -kde_vals, x,
|
154
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
155
|
+
alpha=opt_v['FaceAlpha'],
|
156
|
+
edgecolor=opt_v['EdgeColor'])
|
157
|
+
else:
|
158
|
+
ax.fill_betweenx(y_vals, x, x+kde_vals,
|
159
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
160
|
+
alpha=opt_v['FaceAlpha'],
|
161
|
+
edgecolor=opt_v['EdgeColor'])
|
162
|
+
elif 'f' in opt_v['loc'].lower():
|
163
|
+
ax.fill_betweenx(y_vals, x - kde_vals, x + kde_vals,
|
164
|
+
color=opt_v['FaceColor'][i % len(opt_v['FaceColor'])],
|
165
|
+
alpha=opt_v['FaceAlpha'],
|
166
|
+
edgecolor=opt_v['EdgeColor'])
|
167
|
+
|
168
|
+
def plot_lines(data, opt_l, opt_s, ax):
|
169
|
+
scatter_positions = get_positions(xloc, opt_s['loc'], opt_s['x_width'], data.shape[0])
|
170
|
+
for incol in range(data.shape[1]-1):
|
171
|
+
for irow in range(data.shape[0]):
|
172
|
+
if not np.isnan(data[irow, incol]):
|
173
|
+
if opt_l['LineStyle'] is not None and not opt_l['LineStyle'] =='none':
|
174
|
+
x_data = [scatter_positions[irow, incol], scatter_positions[irow, incol + 1]]
|
175
|
+
y_data = [data[irow, incol], data[irow, incol + 1]]
|
176
|
+
|
177
|
+
|
178
|
+
ax.plot(x_data, y_data,
|
179
|
+
color=opt_l['LineColor'],
|
180
|
+
linestyle=opt_l['LineStyle'],
|
181
|
+
linewidth=opt_l['LineWidth'],
|
182
|
+
alpha=opt_l['LineAlpha'])
|
183
|
+
|
184
|
+
def get_positions(xloc, loc_type, x_width, n_row=None):
|
185
|
+
if 'rand' in loc_type:
|
186
|
+
scatter_positions = np.zeros((n_row, len(xloc)))
|
187
|
+
np.random.seed(111)
|
188
|
+
for i, x in enumerate(xloc):
|
189
|
+
scatter_positions[:, i] = np.random.uniform(x - x_width, x + x_width, n_row)
|
190
|
+
return scatter_positions
|
191
|
+
elif 'l' in loc_type:
|
192
|
+
return np.tile(xloc - x_width,(n_row,1))
|
193
|
+
elif 'r' in loc_type and not 'd' in loc_type:
|
194
|
+
return np.tile(xloc + x_width,(n_row,1))
|
195
|
+
elif 'i' in loc_type:
|
196
|
+
return np.tile(np.concatenate([xloc[:1] + x_width, xloc[1:-1], xloc[-1:] - x_width]),(n_row,1))
|
197
|
+
elif 'o' in loc_type:
|
198
|
+
return np.tile(np.concatenate([xloc[:1] - x_width, xloc[1:-1], xloc[-1:] + x_width]),(n_row,1))
|
199
|
+
else:
|
200
|
+
return np.tile(xloc,(n_row,1))
|
201
|
+
|
202
|
+
opt = kwargs.get('opt',{})
|
203
|
+
ax = kwargs.get('ax',None)
|
204
|
+
if 'ax' not in locals() or ax is None:
|
205
|
+
ax=plt.gca()
|
206
|
+
|
207
|
+
default_colors = np.array([
|
208
|
+
[0, 0, 0],
|
209
|
+
[234, 37, 46],
|
210
|
+
[0, 154, 222],
|
211
|
+
[175, 89, 186],
|
212
|
+
[255, 198, 37],
|
213
|
+
[242, 133, 34]
|
214
|
+
]) / 255.0
|
215
|
+
|
216
|
+
opt.setdefault('c', default_colors)
|
217
|
+
if len(opt['c']) < data.shape[1]:
|
218
|
+
additional_colors = plt.cm.winter(np.linspace(0, 1, data.shape[1] - len(opt['c'])))
|
219
|
+
opt['c'] = np.vstack([opt['c'], additional_colors[:, :3]])
|
220
|
+
|
221
|
+
opt.setdefault('loc', {})
|
222
|
+
opt['loc'].setdefault('go', 0)
|
223
|
+
opt['loc'].setdefault('xloc', np.arange(1, data.shape[1] + 1))
|
224
|
+
|
225
|
+
# export setting
|
226
|
+
opt.setdefault('export', False)
|
227
|
+
opt['export'].setdefault('path', None)
|
228
|
+
print(opt['export'])
|
229
|
+
|
230
|
+
opt.setdefault('b', {})
|
231
|
+
opt['b'].setdefault('go', 0)
|
232
|
+
opt['b'].setdefault('EdgeColor', 'k')
|
233
|
+
opt['b'].setdefault('FaceAlpha', 1)
|
234
|
+
opt['b'].setdefault('EdgeAlpha', 1)
|
235
|
+
opt['b'].setdefault('LineStyle', '-')
|
236
|
+
opt['b'].setdefault('x_width', 0.5)
|
237
|
+
opt['b'].setdefault('ShowBaseLine', 'off')
|
238
|
+
opt['b'].setdefault('loc', 'c')
|
239
|
+
opt['b'].setdefault('FaceColor', opt['c'])
|
240
|
+
|
241
|
+
opt.setdefault('e', {})
|
242
|
+
opt['e'].setdefault('go', 1)
|
243
|
+
opt['e'].setdefault('LineWidth', 1)
|
244
|
+
opt['e'].setdefault('CapLineWidth', 1)
|
245
|
+
opt['e'].setdefault('CapSize', opt['b']['x_width'] * 100 * 0.1)
|
246
|
+
opt['e'].setdefault('Marker', 'none')
|
247
|
+
opt['e'].setdefault('LineStyle', 'none')
|
248
|
+
opt['e'].setdefault('LineColor', 'k')
|
249
|
+
opt['e'].setdefault('LineJoin', 'round')
|
250
|
+
opt['e'].setdefault('MarkerSize', 'auto')
|
251
|
+
opt['e'].setdefault('FaceColor', opt['c'])
|
252
|
+
opt['e'].setdefault('MarkerEdgeColor', 'none')
|
253
|
+
opt['e'].setdefault('Visible', True)
|
254
|
+
opt['e'].setdefault('Orientation', 'vertical')
|
255
|
+
opt['e'].setdefault('error', 'sem')
|
256
|
+
opt['e'].setdefault('loc', 'c')
|
257
|
+
opt['e'].setdefault('x_width', opt['b']['x_width'] / 5)
|
258
|
+
opt['e'].setdefault('cap_dir', 'b')
|
259
|
+
|
260
|
+
opt.setdefault('s', {})
|
261
|
+
opt['s'].setdefault('go', 1)
|
262
|
+
opt['s'].setdefault('x_width', opt['b']['x_width'] / 5)
|
263
|
+
opt['s'].setdefault('Marker', 'o')
|
264
|
+
opt['s'].setdefault('MarkerSize', 6) # Set default size for markers
|
265
|
+
opt['s'].setdefault('LineWidth', 1)
|
266
|
+
opt['s'].setdefault('FaceColor', opt['c'])
|
267
|
+
opt['s'].setdefault('FaceAlpha', 0.6)
|
268
|
+
opt['s'].setdefault('loc', 'random')
|
269
|
+
opt['s'].setdefault('MarkerEdgeColor', None)
|
270
|
+
|
271
|
+
opt.setdefault('bx', {})
|
272
|
+
opt['bx'].setdefault('go', 0)
|
273
|
+
opt['bx'].setdefault('EdgeColor', 'k')
|
274
|
+
opt['bx'].setdefault('FaceAlpha', 1)
|
275
|
+
opt['bx'].setdefault('EdgeAlpha', 1)
|
276
|
+
opt['bx'].setdefault('LineStyle', '-')
|
277
|
+
opt['bx'].setdefault('x_width', 0.5)
|
278
|
+
opt['bx'].setdefault('ShowBaseLine', 'off')
|
279
|
+
opt['bx'].setdefault('loc', 'c')
|
280
|
+
opt['bx'].setdefault('FaceColor', opt['c'])
|
281
|
+
opt['bx'].setdefault('Notch', False)
|
282
|
+
opt['bx'].setdefault('MedianStyle', 'line')
|
283
|
+
opt['bx'].setdefault('Outliers', 'on')
|
284
|
+
opt['bx'].setdefault('OutlierMarker', '+')
|
285
|
+
opt['bx'].setdefault('OutlierColor', 'r')
|
286
|
+
opt['bx'].setdefault('OutlierSize', 6)
|
287
|
+
opt['bx'].setdefault('PlotStyle', 'traditional')
|
288
|
+
opt['bx'].setdefault('FactorDirection', 'auto')
|
289
|
+
opt['bx'].setdefault('Whisker', 1.5)
|
290
|
+
opt['bx'].setdefault('Orientation', 'vertical')
|
291
|
+
opt['bx'].setdefault('BoxLineWidth', 1.5)
|
292
|
+
opt['bx'].setdefault('FaceColor', 'k')
|
293
|
+
opt['bx'].setdefault('WhiskerLineStyle', '-')
|
294
|
+
opt['bx'].setdefault('WhiskerLineColor', 'k')
|
295
|
+
opt['bx'].setdefault('WhiskerLineWidth', 1.5)
|
296
|
+
opt['bx'].setdefault('Caps', True)
|
297
|
+
opt['bx'].setdefault('CapLineColor', 'k')
|
298
|
+
opt['bx'].setdefault('CapLineWidth', 1.5)
|
299
|
+
opt['bx'].setdefault('CapSize', 0.35)
|
300
|
+
opt['bx'].setdefault('MedianLineStyle', '-')
|
301
|
+
opt['bx'].setdefault('MedianLineColor', 'k')
|
302
|
+
opt['bx'].setdefault('MedianLineWidth', 1.5)
|
303
|
+
opt['bx'].setdefault('MedianLineTop', False)
|
304
|
+
opt['bx'].setdefault('MeanLine', False)
|
305
|
+
opt['bx'].setdefault('showmeans', opt['bx']['MeanLine'])
|
306
|
+
opt['bx'].setdefault('MeanLineStyle', '-')
|
307
|
+
opt['bx'].setdefault('MeanLineColor', 'b')
|
308
|
+
opt['bx'].setdefault('MeanLineWidth', 1.5)
|
309
|
+
|
310
|
+
# Violin plot options
|
311
|
+
opt.setdefault('v', {})
|
312
|
+
opt['v'].setdefault('go', 1)
|
313
|
+
opt['v'].setdefault('x_width', 0.3)
|
314
|
+
opt['v'].setdefault('loc', 'r')
|
315
|
+
opt['v'].setdefault('EdgeColor', 'none')
|
316
|
+
opt['v'].setdefault('FaceColor', opt['c'])
|
317
|
+
opt['v'].setdefault('FaceAlpha', 0.3)
|
318
|
+
opt['v'].setdefault('BandWidth', 'scott')
|
319
|
+
opt['v'].setdefault('Function', 'pdf')
|
320
|
+
opt['v'].setdefault('Kernel', 'gau')
|
321
|
+
opt['v'].setdefault('NumPoints', 500)
|
322
|
+
opt['v'].setdefault('BoundaryCorrection', 'reflection')
|
323
|
+
|
324
|
+
# line plot options
|
325
|
+
opt.setdefault('l', {})
|
326
|
+
opt['l'].setdefault('go', 0)
|
327
|
+
opt['l'].setdefault('LineStyle', '-')
|
328
|
+
opt['l'].setdefault('LineColor', 'k')
|
329
|
+
opt['l'].setdefault('LineWidth', 0.5)
|
330
|
+
opt['l'].setdefault('LineAlpha', 0.5)
|
331
|
+
|
332
|
+
data_m = np.nanmean(data, axis=0)
|
333
|
+
nr, nc = data.shape
|
334
|
+
|
335
|
+
xloc = opt['loc']['xloc']
|
336
|
+
|
337
|
+
if opt['b']['go']:
|
338
|
+
plot_bars(data_m, opt['b'], xloc, ax)
|
339
|
+
|
340
|
+
if opt['e']['go']:
|
341
|
+
plot_errors(data, data_m, opt['e'], xloc, ax)
|
342
|
+
|
343
|
+
if opt['s']['go']:
|
344
|
+
plot_scatter(data, opt['s'], xloc, ax)
|
345
|
+
|
346
|
+
if opt['bx']['go']:
|
347
|
+
plot_boxplot(data, opt['bx'], xloc, ax)
|
348
|
+
if opt['v']['go']:
|
349
|
+
plot_violin(data, opt['v'], xloc, ax)
|
350
|
+
if opt['l']['go'] and opt['s']['go']:
|
351
|
+
plot_lines(data, opt['l'], opt['s'], ax)
|
352
|
+
|
353
|
+
return ax
|
354
|
+
|
355
|
+
# from py2ls.ips import get_color,figsets
|
356
|
+
# opt={}
|
357
|
+
# opt = {
|
358
|
+
# 'export':{'path':get_cwd()},
|
359
|
+
# 'c': get_color(5,cmap='jet',by='linspace'), # Custom colors for 3 categories
|
360
|
+
# 'b': {
|
361
|
+
# 'go': 0,
|
362
|
+
# 'x_width': 0.85,
|
363
|
+
# 'FaceAlpha': 0.7,
|
364
|
+
# 'EdgeColor':'none'
|
365
|
+
# },
|
366
|
+
# 'e': {
|
367
|
+
# 'loc':'r',
|
368
|
+
# 'go': 1,
|
369
|
+
# 'error': 'sem',
|
370
|
+
# 'Marker':'d',
|
371
|
+
# 'CapSize': 1,
|
372
|
+
# 'LineWidth':1,
|
373
|
+
# 'CapLineWidth':8,
|
374
|
+
# 'LineStyle':'--',
|
375
|
+
# 'MarkerSize':6,
|
376
|
+
# 'LineColor':'k',
|
377
|
+
# 'FaceColor':get_color(10),
|
378
|
+
# 'MarkerEdgeColor':'none',
|
379
|
+
# 'Visible':True
|
380
|
+
# },
|
381
|
+
# 's': {
|
382
|
+
# 'go': 1,
|
383
|
+
# 'x_width':0.2,
|
384
|
+
# 'loc':'random',
|
385
|
+
# 'Marker': 'o',
|
386
|
+
# # 'MarkerSize': 20,
|
387
|
+
# 'FaceAlpha': 1,
|
388
|
+
# 'FaceColor':'k',
|
389
|
+
# 'LineWidth':1
|
390
|
+
|
391
|
+
# },
|
392
|
+
# 'bx':{
|
393
|
+
# 'go':1,
|
394
|
+
# 'FaceAlpha':0.8,
|
395
|
+
# 'EdgeColor':'none',
|
396
|
+
# 'loc':'c',
|
397
|
+
# 'x_width':0.2,
|
398
|
+
# 'WhiskerLineWidth':1,
|
399
|
+
# 'MedianLineWidth':2,
|
400
|
+
# # 'MedianLineColor':'r',
|
401
|
+
# 'OutlierMarker':'+',
|
402
|
+
# 'OutlierColor':'r',
|
403
|
+
# 'CapSize':.2,
|
404
|
+
# # 'Caps':False,
|
405
|
+
# # 'CapLineColor':'r',
|
406
|
+
# # 'CapLineWidth':8,
|
407
|
+
# # 'MeanLine':True,
|
408
|
+
# # 'FaceColor':['r','g','b','m','c']
|
409
|
+
# },
|
410
|
+
# 'v':{
|
411
|
+
# 'go':0,
|
412
|
+
# 'loc':'r',
|
413
|
+
# 'x_width':0.2,
|
414
|
+
# 'FaceAlpha':0.51,
|
415
|
+
# },
|
416
|
+
# 'l':{
|
417
|
+
# 'go':1,
|
418
|
+
# 'LineColor':'k'
|
419
|
+
# }
|
420
|
+
# }
|
421
|
+
# data1 = np.random.rand(10, 5)
|
422
|
+
# data2 = np.random.rand(10, 5)
|
423
|
+
# fig, axs=plt.subplots(1,2,figsize=(6,2.5))
|
424
|
+
# catplot(data1, opt=opt,ax=axs[0])
|
425
|
+
# catplot(data2, opt=opt,ax=axs[1])
|
426
|
+
# figsets(sp=5,
|
427
|
+
# ax=axs[0],
|
428
|
+
# xticks=np.arange(1,6,1),
|
429
|
+
# xtickslabel=['glua1','glua2','a','b','c'],
|
430
|
+
# xlabel='proteins',
|
431
|
+
# xangle=90,
|
432
|
+
# yticks=np.arange(0,2,0.5),
|
433
|
+
# xlim=[0.75, 5.1],
|
434
|
+
# ticks=dict(pad=1,c='k'))
|
435
|
+
|
436
|
+
# figsave("/Users/macjianfeng/Dropbox/Downloads/",'test.pdf')
|
437
|
+
|