py2ls 0.1.9.3__py3-none-any.whl → 0.1.9.5__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/COMMIT_EDITMSG +1 -1
- py2ls/.git/FETCH_HEAD +1 -1
- py2ls/.git/index +0 -0
- py2ls/.git/logs/HEAD +1 -0
- py2ls/.git/logs/refs/heads/main +1 -0
- py2ls/.git/logs/refs/remotes/origin/HEAD +2 -0
- py2ls/.git/logs/refs/remotes/origin/main +1 -0
- py2ls/.git/objects/12/c2808a1b3a4d0892a4154dfba1e2ae3770fa73 +0 -0
- py2ls/.git/objects/1c/9314c5f69b9390068a2a8616875d974849d71f +0 -0
- py2ls/.git/objects/2a/ae95d517d213b660bf4f65a4e0cfae7bb893eb +0 -0
- py2ls/.git/objects/34/9e31b6a3634cea102ce5588b98c11cc1738605 +0 -0
- py2ls/.git/objects/45/b1b6178bacbfc997811a998b5cc60c1ea7fac8 +0 -0
- py2ls/.git/objects/57/63d0c52f5c9c69e89d514a1f96034947abe21a +0 -0
- py2ls/.git/objects/59/380c4c26bdcd4d9b71ae3e2e35f05b3f26c5ab +0 -0
- py2ls/.git/objects/66/6227eeeba24073e63811e89f1449f3d958f183 +0 -0
- py2ls/.git/objects/66/c998778721d424bd0aae80602dabbffa93af2e +0 -0
- py2ls/.git/objects/6d/c2cdf4a84e538e5d4777486aeff87e42f41799 +2 -0
- py2ls/.git/objects/72/245a05b0966011cb381e6b32b0465000e969ab +0 -0
- py2ls/.git/objects/72/e4179337639859678ddaecf38b16f33aaec8e1 +0 -0
- py2ls/.git/objects/a1/906da89d1174f74867800c74c43af36253bd5e +0 -0
- py2ls/.git/objects/d2/992df305f4b56a466a2f221aeb182ddd20f418 +0 -0
- py2ls/.git/objects/dc/c2bdbafb3296e09d9ee4955cfa55d275825f94 +5 -0
- py2ls/.git/objects/dc/cdbd4266765d840be2ae35ab1752a0fa312c16 +0 -0
- py2ls/.git/objects/e2/f2f8f4c25e62a297fc55f36acc6b01cfbab76f +3 -0
- py2ls/.git/objects/ea/3a18cc75e53792744ef754e05d3f4481768c13 +0 -0
- py2ls/.git/objects/ec/40fd8bf8e4c342534a9fc020289e402ba6bc9d +0 -0
- py2ls/.git/objects/f4/ba7f815b886797b73fede071d86e0c134d2bc7 +0 -0
- py2ls/.git/objects/f6/44a8ff56fa035105fc517cbb1ac46c3d8e349a +0 -0
- py2ls/.git/refs/heads/main +1 -1
- py2ls/.git/refs/remotes/origin/main +1 -1
- py2ls/data/styles/example/style1.pdf +0 -0
- py2ls/data/styles/example/style2.pdf +0 -0
- py2ls/data/styles/example/style3.pdf +0 -0
- py2ls/data/styles/example/style4.pdf +0 -0
- py2ls/data/styles/example/style5.pdf +0 -0
- py2ls/data/styles/example/style6.pdf +0 -0
- py2ls/data/styles/example/style7.pdf +0 -0
- py2ls/data/styles/example/style8.pdf +0 -0
- py2ls/data/styles/example/style9.pdf +0 -0
- py2ls/data/styles/style6.json +31 -20
- py2ls/data/styles/style7.json +201 -0
- py2ls/data/styles/style8.json +199 -0
- py2ls/data/styles/style9.json +215 -0
- py2ls/netfinder.py +0 -8
- py2ls/plot.py +561 -126
- py2ls/stats.py +182 -372
- {py2ls-0.1.9.3.dist-info → py2ls-0.1.9.5.dist-info}/METADATA +1 -1
- {py2ls-0.1.9.3.dist-info → py2ls-0.1.9.5.dist-info}/RECORD +50 -17
- {py2ls-0.1.9.3.dist-info → py2ls-0.1.9.5.dist-info}/WHEEL +0 -0
py2ls/plot.py
CHANGED
@@ -9,7 +9,8 @@ import matplotlib.ticker as tck
|
|
9
9
|
from cycler import cycler
|
10
10
|
import logging
|
11
11
|
import os
|
12
|
-
|
12
|
+
|
13
|
+
from .ips import fsave, fload, mkdir, listdir
|
13
14
|
from .stats import *
|
14
15
|
|
15
16
|
# Suppress INFO messages from fontTools
|
@@ -28,8 +29,25 @@ def catplot(data, *args, **kwargs):
|
|
28
29
|
"""
|
29
30
|
|
30
31
|
def plot_bars(data, data_m, opt_b, xloc, ax, label=None):
|
32
|
+
if "l" in opt_b["loc"]:
|
33
|
+
xloc_s = xloc - opt_b["x_dist"]
|
34
|
+
elif "r" in opt_b["loc"]:
|
35
|
+
xloc_s = xloc + opt_b["x_dist"]
|
36
|
+
elif "i" in opt_b["loc"]:
|
37
|
+
xloc_s = xloc
|
38
|
+
xloc_s[:, 0] += opt_b["x_dist"]
|
39
|
+
xloc_s[:, -1] -= opt_b["x_dist"]
|
40
|
+
elif "o" in opt_b["loc"]:
|
41
|
+
xloc_s = xloc
|
42
|
+
xloc_s[:, 0] -= opt_b["x_dist"]
|
43
|
+
xloc_s[:, -1] += opt_b["x_dist"]
|
44
|
+
elif "c" in opt_b["loc"] or "m" in opt_b["loc"]:
|
45
|
+
xloc_s = xloc
|
46
|
+
else:
|
47
|
+
xloc_s = xloc
|
48
|
+
|
31
49
|
bar_positions = get_positions(
|
32
|
-
|
50
|
+
xloc_s, opt_b["loc"], opt_b["x_width"], data.shape[0]
|
33
51
|
)
|
34
52
|
bar_positions = np.nanmean(bar_positions, axis=0)
|
35
53
|
for i, (x, y) in enumerate(zip(bar_positions, data_m)):
|
@@ -60,12 +78,22 @@ def catplot(data, *args, **kwargs):
|
|
60
78
|
|
61
79
|
def plot_errors(data, data_m, opt_e, xloc, ax, label=None):
|
62
80
|
error_positions = get_positions(
|
63
|
-
xloc, opt_e["loc"], opt_e["
|
81
|
+
xloc, opt_e["loc"], opt_e["x_dist"], data.shape[0]
|
64
82
|
)
|
65
83
|
error_positions = np.nanmean(error_positions, axis=0)
|
66
84
|
errors = np.nanstd(data, axis=0, ddof=1)
|
67
85
|
if opt_e["error"] == "sem":
|
68
86
|
errors /= np.sqrt(np.sum(~np.isnan(data), axis=0))
|
87
|
+
if opt_e["LineStyle"] != "none":
|
88
|
+
# draw lines
|
89
|
+
ax.plot(
|
90
|
+
error_positions,
|
91
|
+
data_m,
|
92
|
+
color=opt_e["LineColor"],
|
93
|
+
linestyle=opt_e["LineStyle"],
|
94
|
+
linewidth=opt_e["LineWidth"],
|
95
|
+
alpha=opt_e["LineAlpha"],
|
96
|
+
)
|
69
97
|
|
70
98
|
if not isinstance(opt_e["FaceColor"], list):
|
71
99
|
opt_e["FaceColor"] = [opt_e["FaceColor"]]
|
@@ -144,8 +172,25 @@ def catplot(data, *args, **kwargs):
|
|
144
172
|
)
|
145
173
|
|
146
174
|
def plot_scatter(data, opt_s, xloc, ax, label=None):
|
175
|
+
if "l" in opt_s["loc"]:
|
176
|
+
xloc_s = xloc - opt_s["x_dist"]
|
177
|
+
elif "r" in opt_s["loc"]:
|
178
|
+
xloc_s = xloc + opt_s["x_dist"]
|
179
|
+
elif "i" in opt_s["loc"]:
|
180
|
+
xloc_s = xloc
|
181
|
+
xloc_s[:, 0] += opt_s["x_dist"]
|
182
|
+
xloc_s[:, -1] -= opt_s["x_dist"]
|
183
|
+
elif "o" in opt_s["loc"]:
|
184
|
+
xloc_s = xloc
|
185
|
+
xloc_s[:, 0] -= opt_s["x_dist"]
|
186
|
+
xloc_s[:, -1] += opt_s["x_dist"]
|
187
|
+
elif "c" in opt_s["loc"] or "m" in opt_s["loc"]:
|
188
|
+
xloc_s = xloc
|
189
|
+
else:
|
190
|
+
xloc_s = xloc
|
191
|
+
|
147
192
|
scatter_positions = get_positions(
|
148
|
-
|
193
|
+
xloc_s, opt_s["loc"], opt_s["x_width"], data.shape[0]
|
149
194
|
)
|
150
195
|
for i, (x, y) in enumerate(zip(scatter_positions.T, data.T)):
|
151
196
|
color = to_rgba(opt_s["FaceColor"][i % len(opt_s["FaceColor"])])
|
@@ -177,17 +222,17 @@ def catplot(data, *args, **kwargs):
|
|
177
222
|
|
178
223
|
def plot_boxplot(data, bx_opt, xloc, ax, label=None):
|
179
224
|
if "l" in bx_opt["loc"]:
|
180
|
-
X_bx = xloc - bx_opt["
|
225
|
+
X_bx = xloc - bx_opt["x_dist"]
|
181
226
|
elif "r" in bx_opt["loc"]:
|
182
|
-
X_bx = xloc + bx_opt["
|
227
|
+
X_bx = xloc + bx_opt["x_dist"]
|
183
228
|
elif "i" in bx_opt["loc"]:
|
184
229
|
X_bx = xloc
|
185
|
-
X_bx[:, 0] += bx_opt["
|
186
|
-
X_bx[:, -1] -= bx_opt["
|
230
|
+
X_bx[:, 0] += bx_opt["x_dist"]
|
231
|
+
X_bx[:, -1] -= bx_opt["x_dist"]
|
187
232
|
elif "o" in bx_opt["loc"]:
|
188
233
|
X_bx = xloc
|
189
|
-
X_bx[:, 0] -= bx_opt["
|
190
|
-
X_bx[:, -1] += bx_opt["
|
234
|
+
X_bx[:, 0] -= bx_opt["x_dist"]
|
235
|
+
X_bx[:, -1] += bx_opt["x_dist"]
|
191
236
|
elif "c" in bx_opt["loc"] or "m" in bx_opt["loc"]:
|
192
237
|
X_bx = xloc
|
193
238
|
else:
|
@@ -196,7 +241,8 @@ def catplot(data, *args, **kwargs):
|
|
196
241
|
boxprops = dict(color=bx_opt["EdgeColor"], linewidth=bx_opt["BoxLineWidth"])
|
197
242
|
flierprops = dict(
|
198
243
|
marker=bx_opt["OutlierMarker"],
|
199
|
-
markerfacecolor=bx_opt["
|
244
|
+
markerfacecolor=bx_opt["OutlierFaceColor"],
|
245
|
+
markeredgecolor=bx_opt["OutlierEdgeColor"],
|
200
246
|
markersize=bx_opt["OutlierSize"],
|
201
247
|
)
|
202
248
|
whiskerprops = dict(
|
@@ -258,9 +304,9 @@ def catplot(data, *args, **kwargs):
|
|
258
304
|
if bx_opt["MedianLineTop"]:
|
259
305
|
ax.set_children(ax.get_children()[::-1]) # move median line forward
|
260
306
|
|
261
|
-
def plot_violin(data, opt_v, xloc, ax, label=None):
|
307
|
+
def plot_violin(data, opt_v, xloc, ax, label=None, vertical=True):
|
262
308
|
violin_positions = get_positions(
|
263
|
-
xloc, opt_v["loc"], opt_v["
|
309
|
+
xloc, opt_v["loc"], opt_v["x_dist"], data.shape[0]
|
264
310
|
)
|
265
311
|
violin_positions = np.nanmean(violin_positions, axis=0)
|
266
312
|
for i, (x, ys) in enumerate(zip(violin_positions, data.T)):
|
@@ -392,9 +438,158 @@ def catplot(data, *args, **kwargs):
|
|
392
438
|
edgecolor=opt_v["EdgeColor"],
|
393
439
|
)
|
394
440
|
|
441
|
+
def plot_ridgeplot(data, x, y, opt_r, **kwargs_figsets):
|
442
|
+
# in the sns.FacetGrid class, the 'hue' argument is the one that is the one that will be represented by colors with 'palette'
|
443
|
+
if opt_r["column4color"] is None:
|
444
|
+
column4color = x
|
445
|
+
else:
|
446
|
+
column4color = opt_r["column4color"]
|
447
|
+
|
448
|
+
if opt_r["row_labels"] is None:
|
449
|
+
opt_r["row_labels"] = data[x].unique().tolist()
|
450
|
+
|
451
|
+
if isinstance(opt_r["FaceColor"], str):
|
452
|
+
opt_r["FaceColor"] = [opt_r["FaceColor"]]
|
453
|
+
if len(opt_r["FaceColor"]) == 1:
|
454
|
+
opt_r["FaceColor"] = np.tile(
|
455
|
+
opt_r["FaceColor"], [1, len(opt_r["row_labels"])]
|
456
|
+
)[0]
|
457
|
+
if len(opt_r["FaceColor"]) > len(opt_r["row_labels"]):
|
458
|
+
opt_r["FaceColor"] = opt_r["FaceColor"][: len(opt_r["row_labels"])]
|
459
|
+
|
460
|
+
g = sns.FacetGrid(
|
461
|
+
data=data,
|
462
|
+
row=x,
|
463
|
+
hue=column4color,
|
464
|
+
aspect=opt_r["aspect"],
|
465
|
+
height=opt_r["subplot_height"],
|
466
|
+
palette=opt_r["FaceColor"],
|
467
|
+
)
|
468
|
+
|
469
|
+
# kdeplot
|
470
|
+
g.map(
|
471
|
+
sns.kdeplot,
|
472
|
+
y,
|
473
|
+
bw_adjust=opt_r["bw_adjust"],
|
474
|
+
clip_on=opt_r["clip"],
|
475
|
+
fill=opt_r["fill"],
|
476
|
+
alpha=opt_r["FaceAlpha"],
|
477
|
+
linewidth=opt_r["EdgeLineWidth"],
|
478
|
+
)
|
479
|
+
|
480
|
+
# edge / line of kdeplot
|
481
|
+
if opt_r["EdgeColor"] is not None:
|
482
|
+
g.map(
|
483
|
+
sns.kdeplot,
|
484
|
+
y,
|
485
|
+
bw_adjust=opt_r["bw_adjust"],
|
486
|
+
clip_on=opt_r["clip"],
|
487
|
+
color=opt_r["EdgeColor"],
|
488
|
+
lw=opt_r["EdgeLineWidth"],
|
489
|
+
)
|
490
|
+
else:
|
491
|
+
g.map(
|
492
|
+
sns.kdeplot,
|
493
|
+
y,
|
494
|
+
bw_adjust=opt_r["bw_adjust"],
|
495
|
+
clip_on=opt_r["clip"],
|
496
|
+
color=opt_r["EdgeColor"],
|
497
|
+
lw=opt_r["EdgeLineWidth"],
|
498
|
+
)
|
499
|
+
|
500
|
+
# add a horizontal line
|
501
|
+
if opt_r["xLineColor"] is not None:
|
502
|
+
g.map(
|
503
|
+
plt.axhline,
|
504
|
+
y=0,
|
505
|
+
lw=opt_r["xLineWidth"],
|
506
|
+
clip_on=opt_r["clip"],
|
507
|
+
color=opt_r["xLineColor"],
|
508
|
+
)
|
509
|
+
else:
|
510
|
+
g.map(
|
511
|
+
plt.axhline,
|
512
|
+
y=0,
|
513
|
+
lw=opt_r["xLineWidth"],
|
514
|
+
clip_on=opt_r["clip"],
|
515
|
+
)
|
516
|
+
|
517
|
+
if isinstance(opt_r["color_row_label"], str):
|
518
|
+
opt_r["color_row_label"] = [opt_r["color_row_label"]]
|
519
|
+
if len(opt_r["color_row_label"]) == 1:
|
520
|
+
opt_r["color_row_label"] = np.tile(
|
521
|
+
opt_r["color_row_label"], [1, len(opt_r["row_labels"])]
|
522
|
+
)[0]
|
523
|
+
|
524
|
+
# loop over the FacetGrid figure axes (g.axes.flat)
|
525
|
+
for i, ax in enumerate(g.axes.flat):
|
526
|
+
if kwargs_figsets.get("xlim", False):
|
527
|
+
ax.set_xlim(kwargs_figsets.get("xlim", False))
|
528
|
+
if kwargs_figsets.get("xlim", False):
|
529
|
+
ax.set_ylim(kwargs_figsets.get("ylim", False))
|
530
|
+
if i == 0:
|
531
|
+
row_x = opt_r["row_label_loc_xscale"] * np.abs(
|
532
|
+
np.diff(ax.get_xlim())
|
533
|
+
) + np.min(ax.get_xlim())
|
534
|
+
row_y = opt_r["row_label_loc_yscale"] * np.abs(
|
535
|
+
np.diff(ax.get_ylim())
|
536
|
+
) + np.min(ax.get_ylim())
|
537
|
+
ax.set_title(kwargs_figsets.get("title", ""))
|
538
|
+
ax.text(
|
539
|
+
row_x,
|
540
|
+
row_y,
|
541
|
+
opt_r["row_labels"][i],
|
542
|
+
fontweight=opt_r["fontweight"],
|
543
|
+
fontsize=opt_r["fontsize"],
|
544
|
+
color=opt_r["color_row_label"][i],
|
545
|
+
)
|
546
|
+
figsets(**kwargs_figsets)
|
547
|
+
|
548
|
+
# we use matplotlib.Figure.subplots_adjust() function to get the subplots to overlap
|
549
|
+
g.fig.subplots_adjust(hspace=opt_r["subplot_hspace"])
|
550
|
+
|
551
|
+
# eventually we remove axes titles, yticks and spines
|
552
|
+
g.set_titles("")
|
553
|
+
g.set(yticks=[])
|
554
|
+
g.set(ylabel=opt_r["subplot_ylabel"])
|
555
|
+
# if kwargs_figsets:
|
556
|
+
# g.set(**kwargs_figsets)
|
557
|
+
if kwargs_figsets.get("xlim", False):
|
558
|
+
g.set(xlim=kwargs_figsets.get("xlim", False))
|
559
|
+
g.despine(bottom=True, left=True)
|
560
|
+
|
561
|
+
plt.setp(
|
562
|
+
ax.get_xticklabels(),
|
563
|
+
fontsize=opt_r["fontsize"],
|
564
|
+
fontweight=opt_r["fontweight"],
|
565
|
+
)
|
566
|
+
# if opt_r["ylabel"] is None:
|
567
|
+
# opt_r["ylabel"] = y
|
568
|
+
# plt.xlabel(
|
569
|
+
# opt_r["ylabel"], fontweight=opt_r["fontweight"], fontsize=opt_r["fontsize"]
|
570
|
+
# )
|
571
|
+
return g, opt_r
|
572
|
+
|
395
573
|
def plot_lines(data, opt_l, opt_s, ax):
|
574
|
+
if "l" in opt_s["loc"]:
|
575
|
+
xloc_s = xloc - opt_s["x_dist"]
|
576
|
+
elif "r" in opt_s["loc"]:
|
577
|
+
xloc_s = xloc + opt_s["x_dist"]
|
578
|
+
elif "i" in opt_s["loc"]:
|
579
|
+
xloc_s = xloc
|
580
|
+
xloc_s[:, 0] += opt_s["x_dist"]
|
581
|
+
xloc_s[:, -1] -= opt_s["x_dist"]
|
582
|
+
elif "o" in opt_s["loc"]:
|
583
|
+
xloc_s = xloc
|
584
|
+
xloc_s[:, 0] -= opt_s["x_dist"]
|
585
|
+
xloc_s[:, -1] += opt_s["x_dist"]
|
586
|
+
elif "c" in opt_s["loc"] or "m" in opt_s["loc"]:
|
587
|
+
xloc_s = xloc
|
588
|
+
else:
|
589
|
+
xloc_s = xloc
|
590
|
+
|
396
591
|
scatter_positions = get_positions(
|
397
|
-
|
592
|
+
xloc_s, opt_s["loc"], opt_s["x_width"], data.shape[0]
|
398
593
|
)
|
399
594
|
for incol in range(data.shape[1] - 1):
|
400
595
|
for irow in range(data.shape[0]):
|
@@ -448,6 +643,8 @@ def catplot(data, *args, **kwargs):
|
|
448
643
|
"""
|
449
644
|
sort layers
|
450
645
|
"""
|
646
|
+
if "r" in full_order:
|
647
|
+
return ["r"]
|
451
648
|
# Ensure custom_order is a list of strings
|
452
649
|
custom_order = [str(layer) for layer in custom_order]
|
453
650
|
j = 1
|
@@ -468,11 +665,10 @@ def catplot(data, *args, **kwargs):
|
|
468
665
|
# full_order = sort_catplot_layers(custom_order)
|
469
666
|
|
470
667
|
ax = kwargs.get("ax", None)
|
471
|
-
if "ax" not in locals() or ax is None:
|
472
|
-
ax = plt.gca()
|
473
668
|
col = kwargs.get("col", None)
|
669
|
+
report = kwargs.get("report", True)
|
670
|
+
vertical = kwargs.get("vertical", True)
|
474
671
|
if not col:
|
475
|
-
# figsets
|
476
672
|
kw_figsets = kwargs.get("figsets", None)
|
477
673
|
# check the data type
|
478
674
|
if isinstance(data, pd.DataFrame):
|
@@ -481,6 +677,7 @@ def catplot(data, *args, **kwargs):
|
|
481
677
|
y = kwargs.get("y", None)
|
482
678
|
hue = kwargs.get("hue", None)
|
483
679
|
data = df2array(data=data, x=x, y=y, hue=hue)
|
680
|
+
y_max_loc = np.max(data, axis=0)
|
484
681
|
xticklabels = []
|
485
682
|
if hue is not None:
|
486
683
|
# for i in df[x].unique().tolist():
|
@@ -511,21 +708,16 @@ def catplot(data, *args, **kwargs):
|
|
511
708
|
data=df[df[x] == i], dv=y, factor=hue, **stats_param
|
512
709
|
)
|
513
710
|
elif bool(stats_param):
|
514
|
-
res_tmp = FuncMultiCmpt(
|
711
|
+
res_tmp = FuncMultiCmpt(
|
712
|
+
data=df[df[x] == i], dv=y, factor=hue
|
713
|
+
)
|
515
714
|
else:
|
516
715
|
res_tmp = "did not work properly"
|
517
716
|
display_output(res_tmp)
|
518
|
-
xloc_curr = hue_len * (ihue - 1)
|
519
|
-
# add_asterisks(ax,res_tmp,xticks[xloc_curr:xloc_curr+hue_len],legend_hue)
|
520
|
-
# res_tmp = [{"x": i, **res_tmp}]
|
521
|
-
# print("here")
|
522
|
-
# df_=pd.DataFrame([res_tmp])
|
523
|
-
# display(df_['pval'][0].tolist()[0])
|
524
717
|
res = pd.concat(
|
525
|
-
[res, pd.DataFrame([res_tmp])], ignore_index=True
|
718
|
+
[res, pd.DataFrame([res_tmp])], ignore_index=True, axis=0
|
526
719
|
)
|
527
720
|
ihue += 1
|
528
|
-
display_output(res)
|
529
721
|
|
530
722
|
else:
|
531
723
|
# ! stats info
|
@@ -540,9 +732,22 @@ def catplot(data, *args, **kwargs):
|
|
540
732
|
res = None
|
541
733
|
if x and stats_param:
|
542
734
|
if isinstance(stats_param, dict):
|
543
|
-
|
735
|
+
if len(xticklabels) > 2:
|
736
|
+
res = FuncMultiCmpt(data=df, dv=y, factor=x, **stats_param)
|
737
|
+
else:
|
738
|
+
res = FuncCmpt(
|
739
|
+
x1=df.loc[df[x] == xticklabels[0], y].tolist(),
|
740
|
+
x2=df.loc[df[x] == xticklabels[1], y].tolist(),
|
741
|
+
**stats_param,
|
742
|
+
)
|
544
743
|
elif bool(stats_param):
|
545
|
-
|
744
|
+
if len(xticklabels) > 2:
|
745
|
+
res = FuncMultiCmpt(data=df, dv=y, factor=x)
|
746
|
+
else:
|
747
|
+
res = FuncCmpt(
|
748
|
+
x1=df.loc[df[x] == xticklabels[0], y].tolist(),
|
749
|
+
x2=df.loc[df[x] == xticklabels[1], y].tolist(),
|
750
|
+
)
|
546
751
|
else:
|
547
752
|
res = "did not work properly"
|
548
753
|
display_output(res)
|
@@ -567,11 +772,28 @@ def catplot(data, *args, **kwargs):
|
|
567
772
|
"xangle": xangle,
|
568
773
|
}
|
569
774
|
else:
|
570
|
-
|
775
|
+
if isinstance(data, np.ndarray):
|
776
|
+
df = array2df(data)
|
777
|
+
x = "group"
|
778
|
+
y = "value"
|
779
|
+
xticklabels = []
|
780
|
+
stats_param = kwargs.get("stats", False)
|
781
|
+
for i in df[x].unique().tolist():
|
782
|
+
xticklabels.append(i)
|
783
|
+
xticks = np.arange(1, len(xticklabels) + 1).tolist()
|
784
|
+
xticks_x_loc = np.arange(1, len(xticklabels) + 1).tolist()
|
785
|
+
legend_hue = xticklabels
|
786
|
+
default_colors = get_color(len(xticklabels))
|
571
787
|
default_x_width = 0.5
|
572
|
-
|
573
|
-
|
574
|
-
|
788
|
+
res = None
|
789
|
+
if x and stats_param:
|
790
|
+
if isinstance(stats_param, dict):
|
791
|
+
res = FuncMultiCmpt(data=df, dv=y, factor=x, **stats_param)
|
792
|
+
elif bool(stats_param):
|
793
|
+
res = FuncMultiCmpt(data=df, dv=y, factor=x)
|
794
|
+
else:
|
795
|
+
res = "did not work properly"
|
796
|
+
display_output(res)
|
575
797
|
|
576
798
|
# full_order
|
577
799
|
opt = kwargs.get("opt", {})
|
@@ -582,22 +804,27 @@ def catplot(data, *args, **kwargs):
|
|
582
804
|
if "style" in k and "exp" not in k:
|
583
805
|
style_use = v
|
584
806
|
break
|
585
|
-
if style_use:
|
807
|
+
if style_use is not None:
|
586
808
|
try:
|
587
809
|
dir_curr_script = os.path.dirname(os.path.abspath(__file__))
|
588
810
|
dir_style = dir_curr_script + "/data/styles/"
|
589
|
-
|
811
|
+
if isinstance(style_use, str):
|
812
|
+
style_load = fload(dir_style + style_use + ".json")
|
813
|
+
else:
|
814
|
+
style_load = fload(
|
815
|
+
listdir(dir_style, "json").path.tolist()[style_use]
|
816
|
+
)
|
590
817
|
style_load = remove_colors_in_dict(style_load)
|
591
818
|
opt.update(style_load)
|
592
819
|
except:
|
593
|
-
print(f"cannot find the style'{
|
820
|
+
print(f"cannot find the style'{style_use}'")
|
594
821
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
#
|
599
|
-
# )
|
600
|
-
|
822
|
+
color_custom = kwargs.get("c", default_colors)
|
823
|
+
if not isinstance(color_custom, list):
|
824
|
+
color_custom = list(color_custom)
|
825
|
+
# if len(color_custom) < data.shape[1]:
|
826
|
+
# color_custom.extend(get_color(data.shape[1]-len(color_custom),cmap='tab20'))
|
827
|
+
opt.setdefault("c", color_custom)
|
601
828
|
|
602
829
|
opt.setdefault("loc", {})
|
603
830
|
opt["loc"].setdefault("go", 0)
|
@@ -605,58 +832,58 @@ def catplot(data, *args, **kwargs):
|
|
605
832
|
|
606
833
|
# export setting
|
607
834
|
opt.setdefault("style", {})
|
608
|
-
opt["style"].setdefault("export", None)
|
609
|
-
print(opt["style"])
|
610
|
-
|
611
|
-
# opt.setdefault('layer', {})
|
612
835
|
opt.setdefault("layer", ["b", "bx", "e", "v", "s", "l"])
|
613
836
|
|
614
837
|
opt.setdefault("b", {})
|
615
838
|
opt["b"].setdefault("go", 1)
|
616
839
|
opt["b"].setdefault("loc", "c")
|
617
|
-
opt["b"].setdefault("FaceColor",
|
840
|
+
opt["b"].setdefault("FaceColor", color_custom)
|
618
841
|
opt["b"].setdefault("FaceAlpha", 1)
|
619
842
|
opt["b"].setdefault("EdgeColor", "k")
|
620
843
|
opt["b"].setdefault("EdgeAlpha", 1)
|
621
844
|
opt["b"].setdefault("LineStyle", "-")
|
622
845
|
opt["b"].setdefault("LineWidth", 0.8)
|
623
846
|
opt["b"].setdefault("x_width", default_x_width)
|
847
|
+
opt["b"].setdefault("x_dist", opt["b"]["x_width"])
|
624
848
|
opt["b"].setdefault("ShowBaseLine", "off")
|
625
849
|
opt["b"].setdefault("hatch", None)
|
626
850
|
|
627
851
|
opt.setdefault("e", {})
|
628
852
|
opt["e"].setdefault("go", 1)
|
629
853
|
opt["e"].setdefault("loc", "l")
|
630
|
-
opt["e"].setdefault("LineWidth",
|
854
|
+
opt["e"].setdefault("LineWidth", 2)
|
631
855
|
opt["e"].setdefault("CapLineWidth", 1)
|
632
856
|
opt["e"].setdefault("CapSize", 2)
|
633
857
|
opt["e"].setdefault("Marker", "none")
|
634
858
|
opt["e"].setdefault("LineStyle", "none")
|
635
859
|
opt["e"].setdefault("LineColor", "k")
|
860
|
+
opt["e"].setdefault("LineAlpha", 0.5)
|
636
861
|
opt["e"].setdefault("LineJoin", "round")
|
637
862
|
opt["e"].setdefault("MarkerSize", "auto")
|
638
|
-
opt["e"].setdefault("FaceColor",
|
863
|
+
opt["e"].setdefault("FaceColor", color_custom)
|
639
864
|
opt["e"].setdefault("MarkerEdgeColor", "none")
|
640
865
|
opt["e"].setdefault("Visible", True)
|
641
866
|
opt["e"].setdefault("Orientation", "vertical")
|
642
867
|
opt["e"].setdefault("error", "sem")
|
643
868
|
opt["e"].setdefault("x_width", default_x_width / 5)
|
869
|
+
opt["e"].setdefault("x_dist", opt["e"]["x_width"])
|
644
870
|
opt["e"].setdefault("cap_dir", "b")
|
645
871
|
|
646
872
|
opt.setdefault("s", {})
|
647
873
|
opt["s"].setdefault("go", 1)
|
648
874
|
opt["s"].setdefault("loc", "r")
|
649
|
-
opt["s"].setdefault("FaceColor",
|
875
|
+
opt["s"].setdefault("FaceColor", color_custom)
|
650
876
|
opt["s"].setdefault("cmap", None)
|
651
877
|
opt["s"].setdefault("FaceAlpha", 1)
|
652
|
-
opt["s"].setdefault("x_width", default_x_width / 5)
|
878
|
+
opt["s"].setdefault("x_width", default_x_width / 5 * 0.5)
|
879
|
+
opt["s"].setdefault("x_dist", opt["s"]["x_width"])
|
653
880
|
opt["s"].setdefault("Marker", "o")
|
654
881
|
opt["s"].setdefault("MarkerSize", 15)
|
655
882
|
opt["s"].setdefault("LineWidth", 0.8)
|
656
883
|
opt["s"].setdefault("MarkerEdgeColor", "k")
|
657
884
|
|
658
885
|
opt.setdefault("l", {})
|
659
|
-
opt["l"].setdefault("go",
|
886
|
+
opt["l"].setdefault("go", 0)
|
660
887
|
opt["l"].setdefault("LineStyle", "-")
|
661
888
|
opt["l"].setdefault("LineColor", "k")
|
662
889
|
opt["l"].setdefault("LineWidth", 0.5)
|
@@ -665,17 +892,19 @@ def catplot(data, *args, **kwargs):
|
|
665
892
|
opt.setdefault("bx", {})
|
666
893
|
opt["bx"].setdefault("go", 0)
|
667
894
|
opt["bx"].setdefault("loc", "r")
|
668
|
-
opt["bx"].setdefault("FaceColor",
|
895
|
+
opt["bx"].setdefault("FaceColor", color_custom)
|
669
896
|
opt["bx"].setdefault("EdgeColor", "k")
|
670
897
|
opt["bx"].setdefault("FaceAlpha", 0.85)
|
671
898
|
opt["bx"].setdefault("EdgeAlpha", 1)
|
672
899
|
opt["bx"].setdefault("LineStyle", "-")
|
673
900
|
opt["bx"].setdefault("x_width", default_x_width / 5)
|
901
|
+
opt["bx"].setdefault("x_dist", opt["bx"]["x_width"])
|
674
902
|
opt["bx"].setdefault("ShowBaseLine", "off")
|
675
903
|
opt["bx"].setdefault("Notch", False)
|
676
904
|
opt["bx"].setdefault("Outliers", "on")
|
677
905
|
opt["bx"].setdefault("OutlierMarker", "+")
|
678
|
-
opt["bx"].setdefault("
|
906
|
+
opt["bx"].setdefault("OutlierFaceColor", "r")
|
907
|
+
opt["bx"].setdefault("OutlierEdgeColor", "k")
|
679
908
|
opt["bx"].setdefault("OutlierSize", 6)
|
680
909
|
# opt['bx'].setdefault('PlotStyle', 'traditional')
|
681
910
|
# opt['bx'].setdefault('FactorDirection', 'auto')
|
@@ -707,16 +936,42 @@ def catplot(data, *args, **kwargs):
|
|
707
936
|
opt.setdefault("v", {})
|
708
937
|
opt["v"].setdefault("go", 0)
|
709
938
|
opt["v"].setdefault("x_width", 0.3)
|
939
|
+
opt["v"].setdefault("x_dist", opt["v"]["x_width"])
|
710
940
|
opt["v"].setdefault("loc", "r")
|
711
941
|
opt["v"].setdefault("EdgeColor", "none")
|
712
|
-
opt["v"].setdefault("FaceColor",
|
713
|
-
opt["v"].setdefault("FaceAlpha",
|
942
|
+
opt["v"].setdefault("FaceColor", color_custom)
|
943
|
+
opt["v"].setdefault("FaceAlpha", 1)
|
714
944
|
opt["v"].setdefault("BandWidth", "scott")
|
715
945
|
opt["v"].setdefault("Function", "pdf")
|
716
946
|
opt["v"].setdefault("Kernel", "gau")
|
717
947
|
opt["v"].setdefault("NumPoints", 500)
|
718
948
|
opt["v"].setdefault("BoundaryCorrection", "reflection")
|
719
949
|
|
950
|
+
# ridgeplot
|
951
|
+
opt.setdefault("r", {})
|
952
|
+
opt["r"].setdefault("go", 0)
|
953
|
+
opt["r"].setdefault("bw_adjust", 1)
|
954
|
+
opt["r"].setdefault("clip", False)
|
955
|
+
opt["r"].setdefault("FaceColor", get_color(20))
|
956
|
+
opt["r"].setdefault("FaceAlpha", 1)
|
957
|
+
opt["r"].setdefault("EdgeLineWidth", 1.5)
|
958
|
+
opt["r"].setdefault("fill", True)
|
959
|
+
opt["r"].setdefault("EdgeColor", "none")
|
960
|
+
opt["r"].setdefault("xLineWidth", opt["r"]["EdgeLineWidth"] + 0.5)
|
961
|
+
opt["r"].setdefault("xLineColor", "none")
|
962
|
+
opt["r"].setdefault("aspect", 8)
|
963
|
+
opt["r"].setdefault("subplot_hspace", -0.3) # overlap subplots
|
964
|
+
opt["r"].setdefault("subplot_height", 0.75)
|
965
|
+
opt["r"].setdefault("subplot_ylabel", "")
|
966
|
+
opt["r"].setdefault("column4color", None)
|
967
|
+
opt["r"].setdefault("row_labels", None)
|
968
|
+
opt["r"].setdefault("row_label_loc_xscale", 0.01)
|
969
|
+
opt["r"].setdefault("row_label_loc_yscale", 0.05)
|
970
|
+
opt["r"].setdefault("fontweight", plt.rcParams["font.weight"])
|
971
|
+
opt["r"].setdefault("fontsize", plt.rcParams["font.size"])
|
972
|
+
opt["r"].setdefault("color_row_label", "k")
|
973
|
+
opt["r"].setdefault("ylabel", None)
|
974
|
+
|
720
975
|
data_m = np.nanmean(data, axis=0)
|
721
976
|
nr, nc = data.shape
|
722
977
|
|
@@ -730,19 +985,25 @@ def catplot(data, *args, **kwargs):
|
|
730
985
|
xloc = np.array(opt["loc"]["xloc"])
|
731
986
|
else:
|
732
987
|
xloc = opt["loc"]["xloc"]
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
988
|
+
if opt["r"]["go"]:
|
989
|
+
layers = sort_catplot_layers(opt["layer"], "r")
|
990
|
+
else:
|
991
|
+
layers = sort_catplot_layers(opt["layer"])
|
992
|
+
|
993
|
+
if ("ax" not in locals() or ax is None) and not opt["r"]["go"]:
|
994
|
+
ax = plt.gca()
|
995
|
+
label = kwargs.get("label", "bar")
|
996
|
+
if label:
|
997
|
+
if "b" in label:
|
998
|
+
legend_which = "b"
|
999
|
+
elif "s" in label:
|
1000
|
+
legend_which = "s"
|
1001
|
+
elif "bx" in label:
|
1002
|
+
legend_which = "bx"
|
1003
|
+
elif "e" in label:
|
1004
|
+
legend_which = "e"
|
1005
|
+
elif "v" in label:
|
1006
|
+
legend_which = "v"
|
746
1007
|
else:
|
747
1008
|
legend_which = None
|
748
1009
|
for layer in layers:
|
@@ -768,46 +1029,100 @@ def catplot(data, *args, **kwargs):
|
|
768
1029
|
plot_boxplot(data, opt["bx"], xloc, ax, label=None)
|
769
1030
|
elif layer == "v" and opt["v"]["go"]:
|
770
1031
|
if legend_which == "v":
|
771
|
-
plot_violin(
|
1032
|
+
plot_violin(
|
1033
|
+
data, opt["v"], xloc, ax, label=legend_hue, vertical=vertical
|
1034
|
+
)
|
772
1035
|
else:
|
773
|
-
plot_violin(data, opt["v"], xloc, ax, label=None)
|
1036
|
+
plot_violin(data, opt["v"], xloc, ax, vertical=vertical, label=None)
|
1037
|
+
elif layer == "r" and opt["r"]["go"]:
|
1038
|
+
kwargs_figsets = kwargs.get("figsets", None)
|
1039
|
+
if x and y:
|
1040
|
+
if kwargs_figsets:
|
1041
|
+
plot_ridgeplot(df, x, y, opt["r"], **kwargs_figsets)
|
1042
|
+
else:
|
1043
|
+
plot_ridgeplot(df, x, y, opt["r"])
|
774
1044
|
elif all([layer == "l", opt["l"]["go"], opt["s"]["go"]]):
|
775
1045
|
plot_lines(data, opt["l"], opt["s"], ax)
|
776
1046
|
|
777
|
-
if kw_figsets is not None:
|
1047
|
+
if kw_figsets is not None and not opt["r"]["go"]:
|
778
1048
|
figsets(ax=ax, **kw_figsets)
|
779
1049
|
show_legend = kwargs.get("show_legend", True)
|
780
|
-
if show_legend:
|
1050
|
+
if show_legend and not opt["r"]["go"]:
|
781
1051
|
ax.legend()
|
782
|
-
|
783
1052
|
# ! add asterisks in the plot
|
784
1053
|
if stats_param:
|
785
|
-
if
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
1054
|
+
if len(xticklabels) >= 1:
|
1055
|
+
if hue is None:
|
1056
|
+
add_asterisks(
|
1057
|
+
ax,
|
1058
|
+
res,
|
1059
|
+
xticks_x_loc,
|
1060
|
+
xticklabels,
|
1061
|
+
y_loc=np.max(data),
|
1062
|
+
report_go=report,
|
1063
|
+
)
|
1064
|
+
else: # hue is not None
|
1065
|
+
ihue = 1
|
1066
|
+
for i in df[x].unique().tolist():
|
1067
|
+
if stats_param:
|
1068
|
+
if isinstance(stats_param, dict):
|
1069
|
+
if "factor" in stats_param.keys():
|
1070
|
+
res_tmp = FuncMultiCmpt(
|
1071
|
+
data=df, dv=y, **stats_param
|
1072
|
+
)
|
1073
|
+
else:
|
1074
|
+
res_tmp = FuncMultiCmpt(
|
1075
|
+
data=df[df[x] == i],
|
1076
|
+
dv=y,
|
1077
|
+
factor=hue,
|
1078
|
+
**stats_param,
|
1079
|
+
)
|
1080
|
+
elif bool(stats_param):
|
796
1081
|
res_tmp = FuncMultiCmpt(
|
797
|
-
data=df[df[x] == i], dv=y, factor=hue
|
1082
|
+
data=df[df[x] == i], dv=y, factor=hue
|
798
1083
|
)
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
1084
|
+
else:
|
1085
|
+
res_tmp = "did not work properly"
|
1086
|
+
xloc_curr = hue_len * (ihue - 1)
|
1087
|
+
|
1088
|
+
add_asterisks(
|
1089
|
+
ax,
|
1090
|
+
res_tmp,
|
1091
|
+
xticks[xloc_curr : xloc_curr + hue_len],
|
1092
|
+
legend_hue,
|
1093
|
+
y_loc=np.max(data),
|
1094
|
+
report_go=report,
|
1095
|
+
)
|
1096
|
+
ihue += 1
|
1097
|
+
else: # 240814: still has some bugs
|
1098
|
+
if isinstance(res, dict):
|
1099
|
+
tab_res = pd.DataFrame(res[1], index=[0])
|
1100
|
+
x1 = df.loc[df[x] == xticklabels[0], y].tolist()
|
1101
|
+
x2 = df.loc[df[x] == xticklabels[1], y].tolist()
|
1102
|
+
tab_res[f"{xticklabels[0]}(mean±sem)"] = [str_mean_sem(x1)]
|
1103
|
+
tab_res[f"{xticklabels[1]}(mean±sem)"] = [str_mean_sem(x2)]
|
1104
|
+
add_asterisks(
|
1105
|
+
ax,
|
1106
|
+
res[1],
|
1107
|
+
xticks_x_loc,
|
1108
|
+
xticklabels,
|
1109
|
+
y_loc=np.max([x1, x2]),
|
1110
|
+
report_go=report,
|
1111
|
+
)
|
1112
|
+
elif isinstance(res, pd.DataFrame):
|
1113
|
+
display(res)
|
1114
|
+
print("still has some bugs")
|
1115
|
+
x1 = df.loc[df[x] == xticklabels[0], y].tolist()
|
1116
|
+
x2 = df.loc[df[x] == xticklabels[1], y].tolist()
|
1117
|
+
add_asterisks(
|
1118
|
+
ax,
|
1119
|
+
res,
|
1120
|
+
xticks_x_loc,
|
1121
|
+
xticklabels,
|
1122
|
+
y_loc=np.max([x1, x2]),
|
1123
|
+
report_go=report,
|
1124
|
+
)
|
1125
|
+
|
811
1126
|
style_export = kwargs.get("style_export", None)
|
812
1127
|
if style_export and (style_export != style_use):
|
813
1128
|
dir_curr_script = os.path.dirname(os.path.abspath(__file__))
|
@@ -843,6 +1158,11 @@ def get_cmap():
|
|
843
1158
|
|
844
1159
|
|
845
1160
|
def read_mplstyle(style_file):
|
1161
|
+
"""
|
1162
|
+
example usage:
|
1163
|
+
style_file = "/ std-colors.mplstyle"
|
1164
|
+
style_dict = read_mplstyle(style_file)
|
1165
|
+
"""
|
846
1166
|
# Load the style file
|
847
1167
|
plt.style.use(style_file)
|
848
1168
|
|
@@ -857,11 +1177,6 @@ def read_mplstyle(style_file):
|
|
857
1177
|
return style_dict
|
858
1178
|
|
859
1179
|
|
860
|
-
# #example usage:
|
861
|
-
# style_file = "/ std-colors.mplstyle"
|
862
|
-
# style_dict = read_mplstyle(style_file)
|
863
|
-
|
864
|
-
|
865
1180
|
def figsets(*args, **kwargs):
|
866
1181
|
"""
|
867
1182
|
usage:
|
@@ -937,7 +1252,6 @@ def figsets(*args, **kwargs):
|
|
937
1252
|
def set_step_1(ax, key, value):
|
938
1253
|
if ("fo" in key) and (("size" in key) or ("sz" in key)):
|
939
1254
|
fontsize = value
|
940
|
-
print(fontsize)
|
941
1255
|
plt.rcParams.update({"font.size": fontsize})
|
942
1256
|
# style
|
943
1257
|
if "st" in key.lower() or "th" in key.lower():
|
@@ -1183,6 +1497,10 @@ def figsets(*args, **kwargs):
|
|
1183
1497
|
if legend_kws:
|
1184
1498
|
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
|
1185
1499
|
ax.legend(**legend_kws)
|
1500
|
+
else:
|
1501
|
+
legend = ax.get_legend()
|
1502
|
+
if legend is not None:
|
1503
|
+
legend.remove()
|
1186
1504
|
|
1187
1505
|
for arg in args:
|
1188
1506
|
if isinstance(arg, matplotlib.axes._axes.Axes):
|
@@ -1238,6 +1556,8 @@ def get_color(
|
|
1238
1556
|
by: str = "start",
|
1239
1557
|
alpha: float = 1.0,
|
1240
1558
|
output: str = "hue",
|
1559
|
+
*args,
|
1560
|
+
**kwargs,
|
1241
1561
|
):
|
1242
1562
|
def cmap2hex(cmap_name):
|
1243
1563
|
cmap_ = matplotlib.pyplot.get_cmap(cmap_name)
|
@@ -1287,6 +1607,8 @@ def get_color(
|
|
1287
1607
|
else:
|
1288
1608
|
return "#{:02X}{:02X}{:02X}".format(r, g, b)
|
1289
1609
|
|
1610
|
+
if cmap == "gray":
|
1611
|
+
cmap = "grey"
|
1290
1612
|
# Determine color list based on cmap parameter
|
1291
1613
|
if "aut" in cmap:
|
1292
1614
|
colorlist = [
|
@@ -1298,7 +1620,38 @@ def get_color(
|
|
1298
1620
|
"#FF9500",
|
1299
1621
|
"#D57DBE",
|
1300
1622
|
]
|
1623
|
+
by = "start"
|
1624
|
+
elif any(["cub" in cmap.lower(), "sns" in cmap.lower()]):
|
1625
|
+
if kwargs:
|
1626
|
+
colorlist = sns.cubehelix_palette(n, **kwargs)
|
1627
|
+
else:
|
1628
|
+
colorlist = sns.cubehelix_palette(
|
1629
|
+
n, start=0.5, rot=-0.75, light=0.85, dark=0.15, as_cmap=False
|
1630
|
+
)
|
1631
|
+
colorlist = [matplotlib.colors.rgb2hex(color) for color in colorlist]
|
1632
|
+
elif any(["hls" in cmap.lower(), "hsl" in cmap.lower()]):
|
1633
|
+
if kwargs:
|
1634
|
+
colorlist = sns.hls_palette(n, **kwargs)
|
1635
|
+
else:
|
1636
|
+
colorlist = sns.hls_palette(n)
|
1637
|
+
colorlist = [matplotlib.colors.rgb2hex(color) for color in colorlist]
|
1638
|
+
elif any(["col" in cmap.lower(), "pal" in cmap.lower()]):
|
1639
|
+
palette, desat, as_cmap = None, None, False
|
1640
|
+
if kwargs:
|
1641
|
+
for k, v in kwargs.items():
|
1642
|
+
if "p" in k:
|
1643
|
+
palette = v
|
1644
|
+
elif "d" in k:
|
1645
|
+
desat = v
|
1646
|
+
elif "a" in k:
|
1647
|
+
as_cmap = v
|
1648
|
+
colorlist = sns.color_palette(
|
1649
|
+
palette=palette, n_colors=n, desat=desat, as_cmap=as_cmap
|
1650
|
+
)
|
1651
|
+
colorlist = [matplotlib.colors.rgb2hex(color) for color in colorlist]
|
1301
1652
|
else:
|
1653
|
+
if by == "start":
|
1654
|
+
by = "linspace"
|
1302
1655
|
colorlist = cmap2hex(cmap)
|
1303
1656
|
|
1304
1657
|
# Determine method for generating color list
|
@@ -1660,30 +2013,112 @@ def remove_colors_in_dict(
|
|
1660
2013
|
|
1661
2014
|
|
1662
2015
|
def add_asterisks(ax, res, xticks_x_loc, xticklabels, **kwargs_funcstars):
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
2016
|
+
if len(xticklabels) > 2:
|
2017
|
+
if isinstance(res, dict):
|
2018
|
+
pval_groups = res["res_tab"]["p-unc"].tolist()[0]
|
2019
|
+
else:
|
2020
|
+
pval_groups = res["res_tab"]["PR(>F)"].tolist()[0]
|
2021
|
+
report_go = kwargs_funcstars.get("report_go", False)
|
2022
|
+
if pval_groups <= 0.05:
|
2023
|
+
A_list = res["res_posthoc"]["A"].tolist()
|
2024
|
+
B_list = res["res_posthoc"]["B"].tolist()
|
2025
|
+
xticklabels_array = np.array(xticklabels)
|
2026
|
+
yscal_ = 0.99
|
2027
|
+
for A, B, P in zip(
|
2028
|
+
res["res_posthoc"]["A"].tolist(),
|
2029
|
+
res["res_posthoc"]["B"].tolist(),
|
2030
|
+
res["res_posthoc"]["p-unc"].tolist(),
|
2031
|
+
):
|
2032
|
+
index_A = np.where(xticklabels_array == A)[0][0]
|
2033
|
+
index_B = np.where(xticklabels_array == B)[0][0]
|
2034
|
+
FuncStars(
|
2035
|
+
ax=ax,
|
2036
|
+
x1=xticks_x_loc[index_A],
|
2037
|
+
x2=xticks_x_loc[index_B],
|
2038
|
+
pval=P,
|
2039
|
+
yscale=yscal_,
|
2040
|
+
**kwargs_funcstars,
|
2041
|
+
)
|
2042
|
+
if P <= 0.05:
|
2043
|
+
yscal_ -= 0.075
|
2044
|
+
if report_go:
|
2045
|
+
try:
|
2046
|
+
if isinstance(res["APA"], list):
|
2047
|
+
APA_str = res["APA"][0]
|
2048
|
+
else:
|
2049
|
+
APA_str = res["APA"]
|
2050
|
+
except:
|
2051
|
+
pass
|
2052
|
+
|
1680
2053
|
FuncStars(
|
1681
2054
|
ax=ax,
|
1682
|
-
x1=
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
2055
|
+
x1=(
|
2056
|
+
xticks_x_loc[0] - (xticks_x_loc[-1] - xticks_x_loc[0]) / 3
|
2057
|
+
if xticks_x_loc[0] > 1
|
2058
|
+
else xticks_x_loc[0]
|
2059
|
+
),
|
2060
|
+
x2=(
|
2061
|
+
xticks_x_loc[0] - (xticks_x_loc[-1] - xticks_x_loc[0]) / 3
|
2062
|
+
if xticks_x_loc[0] > 1
|
2063
|
+
else xticks_x_loc[0]
|
2064
|
+
),
|
2065
|
+
pval=None,
|
2066
|
+
report_scale=np.random.uniform(0.7, 0.99),
|
2067
|
+
report=APA_str,
|
2068
|
+
fontsize_note=8,
|
2069
|
+
)
|
2070
|
+
else:
|
2071
|
+
if isinstance(res, tuple):
|
2072
|
+
res = res[1]
|
2073
|
+
pval_groups = res["pval"]
|
2074
|
+
FuncStars(
|
2075
|
+
ax=ax,
|
2076
|
+
x1=1,
|
2077
|
+
x2=2,
|
2078
|
+
pval=pval_groups,
|
2079
|
+
**kwargs_funcstars,
|
2080
|
+
)
|
2081
|
+
else:
|
2082
|
+
pval_groups = res["pval"]
|
2083
|
+
FuncStars(
|
2084
|
+
ax=ax,
|
2085
|
+
x1=1,
|
2086
|
+
x2=2,
|
2087
|
+
pval=pval_groups,
|
1686
2088
|
**kwargs_funcstars,
|
1687
2089
|
)
|
1688
|
-
|
1689
|
-
|
2090
|
+
|
2091
|
+
|
2092
|
+
def style_examples(
|
2093
|
+
dir_save="/Users/macjianfeng/Dropbox/github/python/py2ls/.venv/lib/python3.12/site-packages/py2ls/data/styles/example",
|
2094
|
+
):
|
2095
|
+
f = listdir(
|
2096
|
+
"/Users/macjianfeng/Dropbox/github/python/py2ls/.venv/lib/python3.12/site-packages/py2ls/data/styles/",
|
2097
|
+
kind=".json",
|
2098
|
+
)
|
2099
|
+
display(f.sample(2))
|
2100
|
+
# def style_example(dir_save,)
|
2101
|
+
# Sample data creation
|
2102
|
+
np.random.seed(42)
|
2103
|
+
categories = ["A", "B", "C", "D", "E"]
|
2104
|
+
data = pd.DataFrame(
|
2105
|
+
{
|
2106
|
+
"value": np.concatenate(
|
2107
|
+
[np.random.normal(loc, 0.4, 100) for loc in range(5)]
|
2108
|
+
),
|
2109
|
+
"category": np.repeat(categories, 100),
|
2110
|
+
}
|
2111
|
+
)
|
2112
|
+
for i in range(f.num[0]):
|
2113
|
+
plt.figure()
|
2114
|
+
_, _ = catplot(
|
2115
|
+
data=data,
|
2116
|
+
x="category",
|
2117
|
+
y="value",
|
2118
|
+
style=i,
|
2119
|
+
figsets=dict(title=f"style{i+1} or style idx={i}"),
|
2120
|
+
)
|
2121
|
+
figsave(
|
2122
|
+
dir_save,
|
2123
|
+
f"{f.name[i]}.pdf",
|
2124
|
+
)
|