py2ls 0.1.8.7__py3-none-any.whl → 0.1.8.9__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/ips.py
CHANGED
@@ -45,7 +45,8 @@ from langdetect import detect
|
|
45
45
|
from duckduckgo_search import DDGS
|
46
46
|
|
47
47
|
from . import netfinder
|
48
|
-
|
48
|
+
|
49
|
+
# from .plot import get_color
|
49
50
|
|
50
51
|
try:
|
51
52
|
get_ipython().run_line_magic("load_ext", "autoreload")
|
@@ -1354,18 +1355,12 @@ def fsave(
|
|
1354
1355
|
|
1355
1356
|
def save_json(fpath_fname, var_dict_or_df):
|
1356
1357
|
with open(fpath_fname, "w") as f_json:
|
1357
|
-
# Check if var_dict_or_df is a DataFrame
|
1358
1358
|
if isinstance(var_dict_or_df, pd.DataFrame):
|
1359
|
-
# Convert DataFrame to a list of dictionaries
|
1360
1359
|
var_dict_or_df = var_dict_or_df.to_dict(orient="dict")
|
1361
|
-
|
1362
|
-
# Check if var_dict_or_df is a dictionary
|
1363
1360
|
if isinstance(var_dict_or_df, dict):
|
1364
|
-
# Convert NumPy arrays to lists
|
1365
1361
|
for key, value in var_dict_or_df.items():
|
1366
1362
|
if isinstance(value, np.ndarray):
|
1367
1363
|
var_dict_or_df[key] = value.tolist()
|
1368
|
-
|
1369
1364
|
# Save the dictionary or list of dictionaries to a JSON file
|
1370
1365
|
json.dump(var_dict_or_df, f_json, indent=4)
|
1371
1366
|
|
py2ls/plot.py
CHANGED
@@ -4,7 +4,11 @@ import pandas as pd
|
|
4
4
|
from matplotlib.colors import to_rgba
|
5
5
|
from scipy.stats import gaussian_kde
|
6
6
|
|
7
|
+
import matplotlib
|
8
|
+
import matplotlib.ticker as tck
|
9
|
+
from cycler import cycler
|
7
10
|
import logging
|
11
|
+
from .ips import fsave
|
8
12
|
|
9
13
|
# Suppress INFO messages from fontTools
|
10
14
|
logging.getLogger("fontTools").setLevel(logging.WARNING)
|
@@ -18,30 +22,43 @@ def catplot(data, *args, **kwargs):
|
|
18
22
|
data (array): data matrix
|
19
23
|
"""
|
20
24
|
|
21
|
-
def plot_bars(data, data_m, opt_b, xloc, ax):
|
25
|
+
def plot_bars(data, data_m, opt_b, xloc, ax, label=None):
|
22
26
|
bar_positions = get_positions(
|
23
27
|
xloc, opt_b["loc"], opt_b["x_width"], data.shape[0]
|
24
28
|
)
|
25
29
|
bar_positions = np.nanmean(bar_positions, axis=0)
|
26
30
|
for i, (x, y) in enumerate(zip(bar_positions, data_m)):
|
27
31
|
color = to_rgba(opt_b["FaceColor"][i % len(opt_b["FaceColor"])])
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
if label is not None and i < len(label):
|
33
|
+
ax.bar(
|
34
|
+
x,
|
35
|
+
y,
|
36
|
+
width=opt_b["x_width"],
|
37
|
+
color=color,
|
38
|
+
edgecolor=opt_b["EdgeColor"],
|
39
|
+
alpha=opt_b["FaceAlpha"],
|
40
|
+
linewidth=opt_b["LineWidth"],
|
41
|
+
hatch=opt_b["hatch"],
|
42
|
+
label=label[i],
|
43
|
+
)
|
44
|
+
else:
|
45
|
+
ax.bar(
|
46
|
+
x,
|
47
|
+
y,
|
48
|
+
width=opt_b["x_width"],
|
49
|
+
color=color,
|
50
|
+
edgecolor=opt_b["EdgeColor"],
|
51
|
+
alpha=opt_b["FaceAlpha"],
|
52
|
+
linewidth=opt_b["LineWidth"],
|
53
|
+
hatch=opt_b["hatch"],
|
54
|
+
)
|
38
55
|
|
39
|
-
def plot_errors(data, data_m, opt_e, xloc, ax):
|
56
|
+
def plot_errors(data, data_m, opt_e, xloc, ax, label=None):
|
40
57
|
error_positions = get_positions(
|
41
58
|
xloc, opt_e["loc"], opt_e["x_width"], data.shape[0]
|
42
59
|
)
|
43
60
|
error_positions = np.nanmean(error_positions, axis=0)
|
44
|
-
errors = np.nanstd(data, axis=0)
|
61
|
+
errors = np.nanstd(data, axis=0, ddof=1)
|
45
62
|
if opt_e["error"] == "sem":
|
46
63
|
errors /= np.sqrt(np.sum(~np.isnan(data), axis=0))
|
47
64
|
|
@@ -50,59 +67,110 @@ def catplot(data, *args, **kwargs):
|
|
50
67
|
if not isinstance(opt_e["MarkerEdgeColor"], list):
|
51
68
|
opt_e["MarkerEdgeColor"] = [opt_e["MarkerEdgeColor"]]
|
52
69
|
for i, (x, y, err) in enumerate(zip(error_positions, data_m, errors)):
|
53
|
-
if
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
if label is not None and i < len(label):
|
71
|
+
if opt_e["MarkerSize"] == "auto":
|
72
|
+
ax.errorbar(
|
73
|
+
x,
|
74
|
+
y,
|
75
|
+
yerr=err,
|
76
|
+
fmt=opt_e["Marker"],
|
77
|
+
ecolor=opt_e["LineColor"],
|
78
|
+
elinewidth=opt_e["LineWidth"],
|
79
|
+
lw=opt_e["LineWidth"],
|
80
|
+
ls=opt_e["LineStyle"],
|
81
|
+
capsize=opt_e["CapSize"],
|
82
|
+
capthick=opt_e["CapLineWidth"],
|
83
|
+
mec=opt_e["MarkerEdgeColor"][i % len(opt_e["MarkerEdgeColor"])],
|
84
|
+
mfc=opt_e["FaceColor"][i % len(opt_e["FaceColor"])],
|
85
|
+
visible=opt_e["Visible"],
|
86
|
+
label=label[i],
|
87
|
+
)
|
88
|
+
else:
|
89
|
+
ax.errorbar(
|
90
|
+
x,
|
91
|
+
y,
|
92
|
+
yerr=err,
|
93
|
+
fmt=opt_e["Marker"],
|
94
|
+
ecolor=opt_e["LineColor"],
|
95
|
+
elinewidth=opt_e["LineWidth"],
|
96
|
+
lw=opt_e["LineWidth"],
|
97
|
+
ls=opt_e["LineStyle"],
|
98
|
+
capsize=opt_e["CapSize"],
|
99
|
+
capthick=opt_e["CapLineWidth"],
|
100
|
+
markersize=opt_e["MarkerSize"],
|
101
|
+
mec=opt_e["MarkerEdgeColor"][i % len(opt_e["MarkerEdgeColor"])],
|
102
|
+
mfc=opt_e["FaceColor"][i % len(opt_e["FaceColor"])],
|
103
|
+
visible=opt_e["Visible"],
|
104
|
+
label=label[i],
|
105
|
+
)
|
69
106
|
else:
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
107
|
+
if opt_e["MarkerSize"] == "auto":
|
108
|
+
ax.errorbar(
|
109
|
+
x,
|
110
|
+
y,
|
111
|
+
yerr=err,
|
112
|
+
fmt=opt_e["Marker"],
|
113
|
+
ecolor=opt_e["LineColor"],
|
114
|
+
elinewidth=opt_e["LineWidth"],
|
115
|
+
lw=opt_e["LineWidth"],
|
116
|
+
ls=opt_e["LineStyle"],
|
117
|
+
capsize=opt_e["CapSize"],
|
118
|
+
capthick=opt_e["CapLineWidth"],
|
119
|
+
mec=opt_e["MarkerEdgeColor"][i % len(opt_e["MarkerEdgeColor"])],
|
120
|
+
mfc=opt_e["FaceColor"][i % len(opt_e["FaceColor"])],
|
121
|
+
visible=opt_e["Visible"],
|
122
|
+
)
|
123
|
+
else:
|
124
|
+
ax.errorbar(
|
125
|
+
x,
|
126
|
+
y,
|
127
|
+
yerr=err,
|
128
|
+
fmt=opt_e["Marker"],
|
129
|
+
ecolor=opt_e["LineColor"],
|
130
|
+
elinewidth=opt_e["LineWidth"],
|
131
|
+
lw=opt_e["LineWidth"],
|
132
|
+
ls=opt_e["LineStyle"],
|
133
|
+
capsize=opt_e["CapSize"],
|
134
|
+
capthick=opt_e["CapLineWidth"],
|
135
|
+
markersize=opt_e["MarkerSize"],
|
136
|
+
mec=opt_e["MarkerEdgeColor"][i % len(opt_e["MarkerEdgeColor"])],
|
137
|
+
mfc=opt_e["FaceColor"][i % len(opt_e["FaceColor"])],
|
138
|
+
visible=opt_e["Visible"],
|
139
|
+
)
|
86
140
|
|
87
|
-
def plot_scatter(data, opt_s, xloc, ax):
|
141
|
+
def plot_scatter(data, opt_s, xloc, ax, label=None):
|
88
142
|
scatter_positions = get_positions(
|
89
143
|
xloc, opt_s["loc"], opt_s["x_width"], data.shape[0]
|
90
144
|
)
|
91
145
|
for i, (x, y) in enumerate(zip(scatter_positions.T, data.T)):
|
92
146
|
color = to_rgba(opt_s["FaceColor"][i % len(opt_s["FaceColor"])])
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
147
|
+
if label is not None and i < len(label):
|
148
|
+
ax.scatter(
|
149
|
+
x,
|
150
|
+
y,
|
151
|
+
color=color,
|
152
|
+
alpha=opt_s["FaceAlpha"],
|
153
|
+
edgecolor=opt_s["MarkerEdgeColor"],
|
154
|
+
s=opt_s["MarkerSize"],
|
155
|
+
marker=opt_s["Marker"],
|
156
|
+
linewidths=opt_s["LineWidth"],
|
157
|
+
cmap=opt_s["cmap"],
|
158
|
+
label=label[i],
|
159
|
+
)
|
160
|
+
else:
|
161
|
+
ax.scatter(
|
162
|
+
x,
|
163
|
+
y,
|
164
|
+
color=color,
|
165
|
+
alpha=opt_s["FaceAlpha"],
|
166
|
+
edgecolor=opt_s["MarkerEdgeColor"],
|
167
|
+
s=opt_s["MarkerSize"],
|
168
|
+
marker=opt_s["Marker"],
|
169
|
+
linewidths=opt_s["LineWidth"],
|
170
|
+
cmap=opt_s["cmap"],
|
171
|
+
)
|
104
172
|
|
105
|
-
def plot_boxplot(data, bx_opt, xloc, ax):
|
173
|
+
def plot_boxplot(data, bx_opt, xloc, ax, label=None):
|
106
174
|
if "l" in bx_opt["loc"]:
|
107
175
|
X_bx = xloc - bx_opt["x_width"]
|
108
176
|
elif "r" in bx_opt["loc"]:
|
@@ -145,6 +213,9 @@ def catplot(data, *args, **kwargs):
|
|
145
213
|
color=bx_opt["MeanLineColor"],
|
146
214
|
linewidth=bx_opt["MeanLineWidth"],
|
147
215
|
)
|
216
|
+
# MeanLine or MedianLine only keep only one
|
217
|
+
if bx_opt["MeanLine"]: # MeanLine has priority
|
218
|
+
bx_opt["MedianLine"] = False
|
148
219
|
bxp = ax.boxplot(
|
149
220
|
data,
|
150
221
|
positions=X_bx,
|
@@ -162,7 +233,11 @@ def catplot(data, *args, **kwargs):
|
|
162
233
|
showmeans=bx_opt["MeanLine"],
|
163
234
|
meanprops=meanprops,
|
164
235
|
widths=bx_opt["x_width"],
|
236
|
+
label=label,
|
165
237
|
)
|
238
|
+
if not bx_opt["MedianLine"]:
|
239
|
+
for median in bxp["medians"]:
|
240
|
+
median.set_visible(False)
|
166
241
|
|
167
242
|
if bx_opt["BoxLineWidth"] < 0.1:
|
168
243
|
bx_opt["EdgeColor"] = "none"
|
@@ -175,19 +250,84 @@ def catplot(data, *args, **kwargs):
|
|
175
250
|
if bx_opt["MedianLineTop"]:
|
176
251
|
ax.set_children(ax.get_children()[::-1]) # move median line forward
|
177
252
|
|
178
|
-
def plot_violin(data, opt_v, xloc, ax):
|
253
|
+
def plot_violin(data, opt_v, xloc, ax, label=None):
|
179
254
|
violin_positions = get_positions(
|
180
255
|
xloc, opt_v["loc"], opt_v["x_width"], data.shape[0]
|
181
256
|
)
|
182
257
|
violin_positions = np.nanmean(violin_positions, axis=0)
|
183
258
|
for i, (x, ys) in enumerate(zip(violin_positions, data.T)):
|
184
259
|
ys = ys[~np.isnan(ys)]
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
260
|
+
kde = gaussian_kde(ys, bw_method=opt_v["BandWidth"])
|
261
|
+
min_val, max_val = ys.min(), ys.max()
|
262
|
+
y_vals = np.linspace(min_val, max_val, opt_v["NumPoints"])
|
263
|
+
kde_vals = kde(y_vals)
|
264
|
+
kde_vals = kde_vals / kde_vals.max() * opt_v["x_width"]
|
265
|
+
if label is not None and i < len(label):
|
266
|
+
if len(ys) > 1:
|
267
|
+
if "r" in opt_v["loc"].lower():
|
268
|
+
ax.fill_betweenx(
|
269
|
+
y_vals,
|
270
|
+
x,
|
271
|
+
x + kde_vals,
|
272
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
273
|
+
alpha=opt_v["FaceAlpha"],
|
274
|
+
edgecolor=opt_v["EdgeColor"],
|
275
|
+
label=label[i],
|
276
|
+
)
|
277
|
+
elif (
|
278
|
+
"l" in opt_v["loc"].lower() and not "f" in opt_v["loc"].lower()
|
279
|
+
):
|
280
|
+
ax.fill_betweenx(
|
281
|
+
y_vals,
|
282
|
+
x - kde_vals,
|
283
|
+
x,
|
284
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
285
|
+
alpha=opt_v["FaceAlpha"],
|
286
|
+
edgecolor=opt_v["EdgeColor"],
|
287
|
+
label=label[i],
|
288
|
+
)
|
289
|
+
elif "o" in opt_v["loc"].lower() or "both" in opt_v["loc"].lower():
|
290
|
+
ax.fill_betweenx(
|
291
|
+
y_vals,
|
292
|
+
x - kde_vals,
|
293
|
+
x + kde_vals,
|
294
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
295
|
+
alpha=opt_v["FaceAlpha"],
|
296
|
+
edgecolor=opt_v["EdgeColor"],
|
297
|
+
label=label[i],
|
298
|
+
)
|
299
|
+
elif "i" in opt_v["loc"].lower():
|
300
|
+
if i % 2 == 1: # odd number
|
301
|
+
ax.fill_betweenx(
|
302
|
+
y_vals,
|
303
|
+
x - kde_vals,
|
304
|
+
x,
|
305
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
306
|
+
alpha=opt_v["FaceAlpha"],
|
307
|
+
edgecolor=opt_v["EdgeColor"],
|
308
|
+
label=label[i],
|
309
|
+
)
|
310
|
+
else:
|
311
|
+
ax.fill_betweenx(
|
312
|
+
y_vals,
|
313
|
+
x,
|
314
|
+
x + kde_vals,
|
315
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
316
|
+
alpha=opt_v["FaceAlpha"],
|
317
|
+
edgecolor=opt_v["EdgeColor"],
|
318
|
+
label=label[i],
|
319
|
+
)
|
320
|
+
elif "f" in opt_v["loc"].lower():
|
321
|
+
ax.fill_betweenx(
|
322
|
+
y_vals,
|
323
|
+
x - kde_vals,
|
324
|
+
x + kde_vals,
|
325
|
+
color=opt_v["FaceColor"][i % len(opt_v["FaceColor"])],
|
326
|
+
alpha=opt_v["FaceAlpha"],
|
327
|
+
edgecolor=opt_v["EdgeColor"],
|
328
|
+
label=label[i],
|
329
|
+
)
|
330
|
+
else:
|
191
331
|
if "r" in opt_v["loc"].lower():
|
192
332
|
ax.fill_betweenx(
|
193
333
|
y_vals,
|
@@ -327,7 +467,7 @@ def catplot(data, *args, **kwargs):
|
|
327
467
|
x = kwargs.get("x", None)
|
328
468
|
y = kwargs.get("y", None)
|
329
469
|
hue = kwargs.get("hue", None)
|
330
|
-
data = df2array(data=data, x=x, y=y, hue=hue)
|
470
|
+
data = df2array(data=data, x=x, y=y, hue=hue)
|
331
471
|
xticklabels = []
|
332
472
|
if hue is not None:
|
333
473
|
for i in df[x].unique().tolist():
|
@@ -337,11 +477,16 @@ def catplot(data, *args, **kwargs):
|
|
337
477
|
hue_len = len(df[hue].unique().tolist())
|
338
478
|
xticks = generate_xticks_with_gap(x_len, hue_len)
|
339
479
|
default_x_width = 0.85
|
480
|
+
legend_hue = df[hue].unique().tolist()
|
481
|
+
default_colors = get_color(hue_len)
|
340
482
|
else:
|
341
483
|
for i in df[x].unique().tolist():
|
342
484
|
xticklabels.append(i)
|
343
|
-
xticks = np.arange(1, len(xticklabels) + 1)
|
485
|
+
xticks = np.arange(1, len(xticklabels) + 1).tolist()
|
486
|
+
legend_hue = xticklabels
|
487
|
+
default_colors = get_color(len(xticklabels))
|
344
488
|
default_x_width = 0.5
|
489
|
+
|
345
490
|
# when the xticklabels are too long, rotate the labels a bit
|
346
491
|
|
347
492
|
xangle = 30 if max([len(i) for i in xticklabels]) > 5 else 0
|
@@ -363,7 +508,7 @@ def catplot(data, *args, **kwargs):
|
|
363
508
|
"xangle": xangle,
|
364
509
|
}
|
365
510
|
else:
|
366
|
-
xticks = np.arange(1, data.shape[1] + 1)
|
511
|
+
xticks = np.arange(1, data.shape[1] + 1).tolist()
|
367
512
|
default_x_width = 0.5
|
368
513
|
xangle = 0
|
369
514
|
|
@@ -372,27 +517,12 @@ def catplot(data, *args, **kwargs):
|
|
372
517
|
ax = kwargs.get("ax", None)
|
373
518
|
if "ax" not in locals() or ax is None:
|
374
519
|
ax = plt.gca()
|
375
|
-
|
376
|
-
default_colors = (
|
377
|
-
np.array(
|
378
|
-
[
|
379
|
-
[0, 0, 0],
|
380
|
-
[234, 37, 46],
|
381
|
-
[0, 154, 222],
|
382
|
-
[175, 89, 186],
|
383
|
-
[255, 198, 37],
|
384
|
-
[242, 133, 34],
|
385
|
-
]
|
386
|
-
)
|
387
|
-
/ 255.0
|
388
|
-
)
|
389
|
-
|
390
520
|
opt.setdefault("c", default_colors)
|
391
|
-
if len(opt["c"]) < data.shape[1]:
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
521
|
+
# if len(opt["c"]) < data.shape[1]:
|
522
|
+
# additional_colors = plt.cm.winter(
|
523
|
+
# np.linspace(0, 1, data.shape[1] - len(opt["c"]))
|
524
|
+
# )
|
525
|
+
# opt["c"] = np.vstack([opt["c"], additional_colors[:, :3]])
|
396
526
|
|
397
527
|
opt.setdefault("loc", {})
|
398
528
|
opt["loc"].setdefault("go", 0)
|
@@ -410,7 +540,7 @@ def catplot(data, *args, **kwargs):
|
|
410
540
|
opt["b"].setdefault("go", 1)
|
411
541
|
opt["b"].setdefault("loc", "c")
|
412
542
|
opt["b"].setdefault("FaceColor", opt["c"])
|
413
|
-
opt["b"].setdefault("FaceAlpha",
|
543
|
+
opt["b"].setdefault("FaceAlpha", 1)
|
414
544
|
opt["b"].setdefault("EdgeColor", "k")
|
415
545
|
opt["b"].setdefault("EdgeAlpha", 1)
|
416
546
|
opt["b"].setdefault("LineStyle", "-")
|
@@ -441,13 +571,13 @@ def catplot(data, *args, **kwargs):
|
|
441
571
|
opt.setdefault("s", {})
|
442
572
|
opt["s"].setdefault("go", 1)
|
443
573
|
opt["s"].setdefault("loc", "r")
|
444
|
-
opt["s"].setdefault("FaceColor",
|
574
|
+
opt["s"].setdefault("FaceColor", "w")
|
445
575
|
opt["s"].setdefault("cmap", None)
|
446
576
|
opt["s"].setdefault("FaceAlpha", 1)
|
447
577
|
opt["s"].setdefault("x_width", opt["b"]["x_width"] / 5)
|
448
578
|
opt["s"].setdefault("Marker", "o")
|
449
|
-
opt["s"].setdefault("MarkerSize",
|
450
|
-
opt["s"].setdefault("LineWidth", 0.
|
579
|
+
opt["s"].setdefault("MarkerSize", 15)
|
580
|
+
opt["s"].setdefault("LineWidth", 0.8)
|
451
581
|
opt["s"].setdefault("MarkerEdgeColor", "k")
|
452
582
|
|
453
583
|
opt.setdefault("l", {})
|
@@ -462,7 +592,7 @@ def catplot(data, *args, **kwargs):
|
|
462
592
|
opt["bx"].setdefault("loc", "r")
|
463
593
|
opt["bx"].setdefault("FaceColor", opt["c"])
|
464
594
|
opt["bx"].setdefault("EdgeColor", "k")
|
465
|
-
opt["bx"].setdefault("FaceAlpha", 0.
|
595
|
+
opt["bx"].setdefault("FaceAlpha", 0.85)
|
466
596
|
opt["bx"].setdefault("EdgeAlpha", 1)
|
467
597
|
opt["bx"].setdefault("LineStyle", "-")
|
468
598
|
opt["bx"].setdefault("x_width", 0.2)
|
@@ -485,6 +615,7 @@ def catplot(data, *args, **kwargs):
|
|
485
615
|
opt["bx"].setdefault("CapLineColor", "k")
|
486
616
|
opt["bx"].setdefault("CapLineWidth", 0.5)
|
487
617
|
opt["bx"].setdefault("CapSize", 0.2)
|
618
|
+
opt["bx"].setdefault("MedianLine", True)
|
488
619
|
opt["bx"].setdefault("MedianLineStyle", "-")
|
489
620
|
opt["bx"].setdefault("MedianStyle", "line")
|
490
621
|
opt["bx"].setdefault("MedianLineColor", "k")
|
@@ -524,115 +655,59 @@ def catplot(data, *args, **kwargs):
|
|
524
655
|
else:
|
525
656
|
xloc = opt["loc"]["xloc"]
|
526
657
|
layers = sort_catplot_layers(opt["layer"])
|
658
|
+
|
659
|
+
label_which = kwargs.get("label_which", "barplot")
|
660
|
+
if "b" in label_which:
|
661
|
+
legend_which = "b"
|
662
|
+
elif "s" in label_which:
|
663
|
+
legend_which = "s"
|
664
|
+
elif "bx" in label_which:
|
665
|
+
legend_which = "bx"
|
666
|
+
elif "e" in label_which:
|
667
|
+
legend_which = "e"
|
668
|
+
elif "v" in label_which:
|
669
|
+
legend_which = "v"
|
670
|
+
else:
|
671
|
+
legend_which = None
|
672
|
+
|
527
673
|
for layer in layers:
|
528
674
|
if layer == "b" and opt["b"]["go"]:
|
529
|
-
|
675
|
+
if legend_which == "b":
|
676
|
+
plot_bars(data, data_m, opt["b"], xloc, ax, label=legend_hue)
|
677
|
+
else:
|
678
|
+
plot_bars(data, data_m, opt["b"], xloc, ax, label=None)
|
530
679
|
elif layer == "e" and opt["e"]["go"]:
|
531
|
-
|
680
|
+
if legend_which == "e":
|
681
|
+
plot_errors(data, data_m, opt["e"], xloc, ax, label=legend_hue)
|
682
|
+
else:
|
683
|
+
plot_errors(data, data_m, opt["e"], xloc, ax, label=None)
|
532
684
|
elif layer == "s" and opt["s"]["go"]:
|
533
|
-
|
685
|
+
if legend_which == "s":
|
686
|
+
plot_scatter(data, opt["s"], xloc, ax, label=legend_hue)
|
687
|
+
else:
|
688
|
+
plot_scatter(data, opt["s"], xloc, ax, label=None)
|
534
689
|
elif layer == "bx" and opt["bx"]["go"]:
|
535
|
-
|
690
|
+
if legend_which == "bx":
|
691
|
+
plot_boxplot(data, opt["bx"], xloc, ax, label=legend_hue)
|
692
|
+
else:
|
693
|
+
plot_boxplot(data, opt["bx"], xloc, ax, label=None)
|
536
694
|
elif layer == "v" and opt["v"]["go"]:
|
537
|
-
|
695
|
+
if legend_which == "v":
|
696
|
+
plot_violin(data, opt["v"], xloc, ax, label=legend_hue)
|
697
|
+
else:
|
698
|
+
plot_violin(data, opt["v"], xloc, ax, label=None)
|
538
699
|
elif all([layer == "l", opt["l"]["go"], opt["s"]["go"]]):
|
539
700
|
plot_lines(data, opt["l"], opt["s"], ax)
|
540
701
|
|
541
702
|
if kw_figsets is not None:
|
542
703
|
figsets(ax=ax, **kw_figsets)
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
# 'c': get_color(5,cmap='jet',by='linspace'), # Custom colors for 3 categories
|
551
|
-
# 'b': {
|
552
|
-
# 'go': 0,
|
553
|
-
# 'x_width': 0.85,
|
554
|
-
# 'FaceAlpha': 0.7,
|
555
|
-
# 'EdgeColor':'none'
|
556
|
-
# },
|
557
|
-
# 'e': {
|
558
|
-
# 'loc':'r',
|
559
|
-
# 'go': 1,
|
560
|
-
# 'error': 'sem',
|
561
|
-
# 'Marker':'d',
|
562
|
-
# 'CapSize': 1,
|
563
|
-
# 'LineWidth':1,
|
564
|
-
# 'CapLineWidth':8,
|
565
|
-
# 'LineStyle':'--',
|
566
|
-
# 'MarkerSize':6,
|
567
|
-
# 'LineColor':'k',
|
568
|
-
# 'FaceColor':get_color(10),
|
569
|
-
# 'MarkerEdgeColor':'none',
|
570
|
-
# 'Visible':True
|
571
|
-
# },
|
572
|
-
# 's': {
|
573
|
-
# 'go': 1,
|
574
|
-
# 'x_width':0.2,
|
575
|
-
# 'loc':'random',
|
576
|
-
# 'Marker': 'o',
|
577
|
-
# # 'MarkerSize': 20,
|
578
|
-
# 'FaceAlpha': 1,
|
579
|
-
# 'FaceColor':'k',
|
580
|
-
# 'LineWidth':1
|
581
|
-
|
582
|
-
# },
|
583
|
-
# 'bx':{
|
584
|
-
# 'go':1,
|
585
|
-
# 'FaceAlpha':0.8,
|
586
|
-
# 'EdgeColor':'none',
|
587
|
-
# 'loc':'c',
|
588
|
-
# 'x_width':0.2,
|
589
|
-
# 'WhiskerLineWidth':1,
|
590
|
-
# 'MedianLineWidth':2,
|
591
|
-
# # 'MedianLineColor':'r',
|
592
|
-
# 'OutlierMarker':'+',
|
593
|
-
# 'OutlierColor':'r',
|
594
|
-
# 'CapSize':.2,
|
595
|
-
# # 'Caps':False,
|
596
|
-
# # 'CapLineColor':'r',
|
597
|
-
# # 'CapLineWidth':8,
|
598
|
-
# # 'MeanLine':True,
|
599
|
-
# # 'FaceColor':['r','g','b','m','c']
|
600
|
-
# },
|
601
|
-
# 'v':{
|
602
|
-
# 'go':0,
|
603
|
-
# 'loc':'r',
|
604
|
-
# 'x_width':0.2,
|
605
|
-
# 'FaceAlpha':0.51,
|
606
|
-
# },
|
607
|
-
# 'l':{
|
608
|
-
# 'go':1,
|
609
|
-
# 'LineColor':'k'
|
610
|
-
# }
|
611
|
-
# }
|
612
|
-
# data1 = np.random.rand(10, 5)
|
613
|
-
# data2 = np.random.rand(10, 5)
|
614
|
-
# fig, axs=plt.subplots(1,2,figsize=(6,2.5))
|
615
|
-
# catplot(data1, opt=opt,ax=axs[0])
|
616
|
-
# catplot(data2, opt=opt,ax=axs[1])
|
617
|
-
# figsets(sp=5,
|
618
|
-
# ax=axs[0],
|
619
|
-
# xticks=np.arange(1,6,1),
|
620
|
-
# xtickslabel=['glua1','glua2','a','b','c'],
|
621
|
-
# xlabel='proteins',
|
622
|
-
# xangle=90,
|
623
|
-
# yticks=np.arange(0,2,0.5),
|
624
|
-
# xlim=[0.75, 5.1],
|
625
|
-
# ticks=dict(pad=1,c='k'))
|
626
|
-
|
627
|
-
# figsave("/Users/macjianfeng/Dropbox/Downloads/",'test.pdf')
|
628
|
-
|
629
|
-
|
630
|
-
import numpy as np
|
631
|
-
import matplotlib
|
632
|
-
import matplotlib.pyplot as plt
|
633
|
-
import matplotlib.ticker as tck
|
634
|
-
import seaborn as sns
|
635
|
-
from cycler import cycler
|
704
|
+
show_legend = kwargs.get("show_legend", True)
|
705
|
+
if show_legend:
|
706
|
+
ax.legend()
|
707
|
+
export_style = kwargs.get("export_style", None)
|
708
|
+
if export_style:
|
709
|
+
fsave(export_style, opt)
|
710
|
+
return ax, opt
|
636
711
|
|
637
712
|
|
638
713
|
def get_cmap():
|
@@ -1283,14 +1358,16 @@ def stdshade(ax=None, *args, **kwargs):
|
|
1283
1358
|
yMean = np.nanmean(y, axis=0)
|
1284
1359
|
if paraStdSem == "sem":
|
1285
1360
|
if smth > 1:
|
1286
|
-
wings = savgol_filter(
|
1361
|
+
wings = savgol_filter(
|
1362
|
+
np.nanstd(y, axis=0, ddof=1) / np.sqrt(y.shape[0]), smth, 1
|
1363
|
+
)
|
1287
1364
|
else:
|
1288
|
-
wings = np.nanstd(y, axis=0) / np.sqrt(y.shape[0])
|
1365
|
+
wings = np.nanstd(y, axis=0, ddof=1) / np.sqrt(y.shape[0])
|
1289
1366
|
elif paraStdSem == "std":
|
1290
1367
|
if smth > 1:
|
1291
|
-
wings = savgol_filter(np.nanstd(y, axis=0), smth, 1)
|
1368
|
+
wings = savgol_filter(np.nanstd(y, axis=0, ddof=1), smth, 1)
|
1292
1369
|
else:
|
1293
|
-
wings = np.nanstd(y, axis=0)
|
1370
|
+
wings = np.nanstd(y, axis=0, ddof=1)
|
1294
1371
|
|
1295
1372
|
# fill_kws = kwargs.get('fill_kws', {})
|
1296
1373
|
# line_kws = kwargs.get('line_kws', {})
|
@@ -1515,27 +1592,37 @@ def padcat(*args, fill_value=np.nan, axis=1, order="row"):
|
|
1515
1592
|
# print("Result of padcat(a, b, c):\n", result2)
|
1516
1593
|
|
1517
1594
|
|
1518
|
-
def sort_rows_move_nan(arr):
|
1595
|
+
def sort_rows_move_nan(arr, sort=False):
|
1519
1596
|
# Handle edge cases where all values are NaN
|
1520
1597
|
if np.all(np.isnan(arr)):
|
1521
1598
|
return arr # Return unchanged if the entire array is NaN
|
1522
1599
|
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
# Sort each row
|
1530
|
-
sorted_arr = np.sort(arr_no_nan, axis=1)
|
1600
|
+
if sort:
|
1601
|
+
# Replace NaNs with a temporary large value for sorting
|
1602
|
+
temp_value = (
|
1603
|
+
np.nanmax(arr[np.isfinite(arr)]) + 1 if np.any(np.isfinite(arr)) else np.inf
|
1604
|
+
)
|
1605
|
+
arr_no_nan = np.where(np.isnan(arr), temp_value, arr)
|
1531
1606
|
|
1532
|
-
|
1533
|
-
|
1607
|
+
# Sort each row
|
1608
|
+
sorted_arr = np.sort(arr_no_nan, axis=1)
|
1534
1609
|
|
1535
|
-
|
1610
|
+
# Move NaNs to the end
|
1611
|
+
result_arr = np.where(sorted_arr == temp_value, np.nan, sorted_arr)
|
1612
|
+
else:
|
1613
|
+
result_rows = []
|
1614
|
+
for row in arr:
|
1615
|
+
# Separate non-NaN and NaN values
|
1616
|
+
non_nan_values = row[~np.isnan(row)]
|
1617
|
+
nan_count = np.isnan(row).sum()
|
1618
|
+
# Create a new row with non-NaN values followed by NaNs
|
1619
|
+
new_row = np.concatenate([non_nan_values, [np.nan] * nan_count])
|
1620
|
+
result_rows.append(new_row)
|
1621
|
+
# Convert the list of rows back into a 2D NumPy array
|
1622
|
+
result_arr = np.array(result_rows)
|
1623
|
+
|
1624
|
+
# Remove rows/columns that contain only NaNs
|
1536
1625
|
clean_arr = result_arr[~np.isnan(result_arr).all(axis=1)]
|
1537
|
-
|
1538
|
-
# Remove columns that contain only NaNs
|
1539
1626
|
clean_arr_ = clean_arr[:, ~np.isnan(clean_arr).all(axis=0)]
|
1540
1627
|
|
1541
1628
|
return clean_arr_
|
@@ -1550,8 +1637,8 @@ def df2array(data: pd.DataFrame, x, y, hue=None, sort=False):
|
|
1550
1637
|
cat_x = data[x].unique().tolist()
|
1551
1638
|
for i, x_ in enumerate(cat_x):
|
1552
1639
|
new_ = data.loc[data[x] == x_, y].to_list()
|
1553
|
-
a = padcat(a, new_, axis=0)
|
1554
|
-
return sort_rows_move_nan(a)
|
1640
|
+
a = padcat(a, new_, axis=0)
|
1641
|
+
return sort_rows_move_nan(a).T
|
1555
1642
|
else:
|
1556
1643
|
a = []
|
1557
1644
|
if sort:
|
@@ -1564,7 +1651,7 @@ def df2array(data: pd.DataFrame, x, y, hue=None, sort=False):
|
|
1564
1651
|
for j, hue_ in enumerate(cat_hue):
|
1565
1652
|
new_ = data.loc[(data[x] == x_) & (data[hue] == hue_), y].to_list()
|
1566
1653
|
a = padcat(a, new_, axis=0)
|
1567
|
-
return sort_rows_move_nan(a)
|
1654
|
+
return sort_rows_move_nan(a).T
|
1568
1655
|
|
1569
1656
|
|
1570
1657
|
def generate_xticks_with_gap(x_len, hue_len):
|
@@ -1585,6 +1672,6 @@ def generate_xticks_with_gap(x_len, hue_len):
|
|
1585
1672
|
for i in range(max(x_len, hue_len), 0, -1) # i iterates from 3 to 1
|
1586
1673
|
]
|
1587
1674
|
concatenated_array = np.concatenate(arrays)
|
1588
|
-
positive_array = concatenated_array[concatenated_array > 0]
|
1675
|
+
positive_array = concatenated_array[concatenated_array > 0].tolist()
|
1589
1676
|
|
1590
1677
|
return positive_array
|
@@ -134,14 +134,14 @@ py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
|
|
134
134
|
py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
|
135
135
|
py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
|
136
136
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
137
|
-
py2ls/ips.py,sha256=
|
137
|
+
py2ls/ips.py,sha256=N7MdOCgJXDQu73YkJQTtDN3RSntzXX7V0MOJ1NYBLEk,100572
|
138
138
|
py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
|
139
|
-
py2ls/plot.py,sha256=
|
139
|
+
py2ls/plot.py,sha256=9_vyFNoPX4c8b0AS3lyFu18QKec5je3f0G8T7di9K9o,63197
|
140
140
|
py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
|
141
141
|
py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
|
142
142
|
py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
|
143
143
|
py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
|
144
144
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
145
|
-
py2ls-0.1.8.
|
146
|
-
py2ls-0.1.8.
|
147
|
-
py2ls-0.1.8.
|
145
|
+
py2ls-0.1.8.9.dist-info/METADATA,sha256=7-nSwoDVg7Yf3lZ8pqIZ6b-voypM-2p9vwDWoSLqGFs,20017
|
146
|
+
py2ls-0.1.8.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
147
|
+
py2ls-0.1.8.9.dist-info/RECORD,,
|
File without changes
|