py2ls 0.1.8.3__py3-none-any.whl → 0.1.8.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/plot.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import matplotlib.pyplot as plt
|
2
2
|
import numpy as np
|
3
|
+
import pandas as pd
|
3
4
|
from matplotlib.colors import to_rgba
|
4
5
|
from scipy.stats import gaussian_kde
|
5
6
|
|
@@ -318,6 +319,33 @@ def catplot(data, *args, **kwargs):
|
|
318
319
|
# custom_order = ['s', 'bx', 'e']
|
319
320
|
# full_order = sort_catplot_layers(custom_order)
|
320
321
|
|
322
|
+
# figsets
|
323
|
+
kw_figsets = kwargs.get("figsets", None)
|
324
|
+
# check the data type
|
325
|
+
if isinstance(data, pd.DataFrame):
|
326
|
+
df = data.copy()
|
327
|
+
x = kwargs.get("x", None)
|
328
|
+
y = kwargs.get("y", None)
|
329
|
+
hue = kwargs.get("hue", None)
|
330
|
+
data = df2array(data=data, x=x, y=y, hue=hue).T
|
331
|
+
xticklabels = []
|
332
|
+
if hue is not None:
|
333
|
+
for i in df[x].unique().tolist():
|
334
|
+
for j in df[hue].unique().tolist():
|
335
|
+
xticklabels.append(i + "-" + j)
|
336
|
+
else:
|
337
|
+
for i in df[x].unique().tolist():
|
338
|
+
xticklabels.append(i)
|
339
|
+
ylabel = y
|
340
|
+
xlabe = x
|
341
|
+
|
342
|
+
kw_figsets = {
|
343
|
+
"ylabel": y,
|
344
|
+
"xlabel": x,
|
345
|
+
"xticklabels": xticklabels,
|
346
|
+
**kw_figsets,
|
347
|
+
}
|
348
|
+
|
321
349
|
# full_order
|
322
350
|
opt = kwargs.get("opt", {})
|
323
351
|
ax = kwargs.get("ax", None)
|
@@ -470,7 +498,10 @@ def catplot(data, *args, **kwargs):
|
|
470
498
|
opt[key].update(kwargs[key])
|
471
499
|
else:
|
472
500
|
opt[key] = kwargs[key]
|
473
|
-
|
501
|
+
if isinstance(opt["loc"]["xloc"], list):
|
502
|
+
xloc = np.array(opt["loc"]["xloc"])
|
503
|
+
else:
|
504
|
+
xloc = opt["loc"]["xloc"]
|
474
505
|
layers = sort_catplot_layers(opt["layer"])
|
475
506
|
for layer in layers:
|
476
507
|
if layer == "b" and opt["b"]["go"]:
|
@@ -485,8 +516,7 @@ def catplot(data, *args, **kwargs):
|
|
485
516
|
plot_violin(data, opt["v"], xloc, ax)
|
486
517
|
elif all([layer == "l", opt["l"]["go"], opt["s"]["go"]]):
|
487
518
|
plot_lines(data, opt["l"], opt["s"], ax)
|
488
|
-
|
489
|
-
kw_figsets = kwargs.get("figsets", None)
|
519
|
+
|
490
520
|
if kw_figsets is not None:
|
491
521
|
figsets(ax=ax, **kw_figsets)
|
492
522
|
return ax
|
@@ -1357,7 +1387,42 @@ def add_colorbar(im, width=None, pad=None, **kwargs):
|
|
1357
1387
|
return fig.colorbar(im, cax=cax, **kwargs) # draw cbar
|
1358
1388
|
|
1359
1389
|
|
1360
|
-
def padcat(*args, fill_value=np.nan, axis=1):
|
1390
|
+
# def padcat(*args, fill_value=np.nan, axis=1):
|
1391
|
+
# """
|
1392
|
+
# Concatenate vectors with padding.
|
1393
|
+
|
1394
|
+
# Parameters:
|
1395
|
+
# *args : variable number of list or 1D arrays
|
1396
|
+
# Input arrays to concatenate.
|
1397
|
+
# fill_value : scalar, optional
|
1398
|
+
# The value to use for padding the shorter lists (default is np.nan).
|
1399
|
+
# axis : int, optional
|
1400
|
+
# The axis along which to concatenate (0 for rows, 1 for columns, default is 0).
|
1401
|
+
|
1402
|
+
# Returns:
|
1403
|
+
# np.ndarray
|
1404
|
+
# A 2D array with the input arrays concatenated along the specified axis, padded with fill_value where necessary.
|
1405
|
+
# """
|
1406
|
+
# if axis == 0:
|
1407
|
+
# # Concatenate along rows
|
1408
|
+
# max_len = max(len(lst) for lst in args)
|
1409
|
+
# result = np.full((len(args), max_len), fill_value)
|
1410
|
+
# for i, lst in enumerate(args):
|
1411
|
+
# result[i, : len(lst)] = lst
|
1412
|
+
# elif axis == 1:
|
1413
|
+
# # Concatenate along columns
|
1414
|
+
# max_len = max(len(lst) for lst in args)
|
1415
|
+
# result = np.full((max_len, len(args)), fill_value)
|
1416
|
+
# for i, lst in enumerate(args):
|
1417
|
+
# result[: len(lst), i] = lst
|
1418
|
+
# else:
|
1419
|
+
# raise ValueError("axis must be 0 or 1")
|
1420
|
+
|
1421
|
+
# return result
|
1422
|
+
import numpy as np
|
1423
|
+
|
1424
|
+
|
1425
|
+
def padcat(*args, fill_value=np.nan, axis=1, order="row"):
|
1361
1426
|
"""
|
1362
1427
|
Concatenate vectors with padding.
|
1363
1428
|
|
@@ -1367,25 +1432,78 @@ def padcat(*args, fill_value=np.nan, axis=1):
|
|
1367
1432
|
fill_value : scalar, optional
|
1368
1433
|
The value to use for padding the shorter lists (default is np.nan).
|
1369
1434
|
axis : int, optional
|
1370
|
-
The axis along which to concatenate (0 for rows, 1 for columns, default is
|
1435
|
+
The axis along which to concatenate (0 for rows, 1 for columns, default is 1).
|
1371
1436
|
|
1372
1437
|
Returns:
|
1373
1438
|
np.ndarray
|
1374
|
-
A 2D array with the input arrays concatenated along the specified axis,
|
1439
|
+
A 2D array with the input arrays concatenated along the specified axis,
|
1440
|
+
padded with fill_value where necessary.
|
1375
1441
|
"""
|
1442
|
+
# Convert all inputs to 1D NumPy arrays
|
1443
|
+
if "ro" in order.lower():
|
1444
|
+
order = "C" # in row
|
1445
|
+
else:
|
1446
|
+
order = "F" # column
|
1447
|
+
arrays = [np.asarray(arg).flatten(order=order) for arg in args]
|
1448
|
+
|
1376
1449
|
if axis == 0:
|
1377
1450
|
# Concatenate along rows
|
1378
|
-
max_len = max(
|
1379
|
-
result = np.full((len(
|
1380
|
-
for i,
|
1381
|
-
result[i, :
|
1451
|
+
max_len = max(arr.size for arr in arrays)
|
1452
|
+
result = np.full((len(arrays), max_len), fill_value)
|
1453
|
+
for i, arr in enumerate(arrays):
|
1454
|
+
result[i, : arr.size] = arr
|
1382
1455
|
elif axis == 1:
|
1383
1456
|
# Concatenate along columns
|
1384
|
-
max_len = max(
|
1385
|
-
result = np.full((max_len, len(
|
1386
|
-
for i,
|
1387
|
-
result[:
|
1457
|
+
max_len = max(arr.size for arr in arrays)
|
1458
|
+
result = np.full((max_len, len(arrays)), fill_value)
|
1459
|
+
for i, arr in enumerate(arrays):
|
1460
|
+
result[: arr.size, i] = arr
|
1388
1461
|
else:
|
1389
1462
|
raise ValueError("axis must be 0 or 1")
|
1390
1463
|
|
1391
1464
|
return result
|
1465
|
+
|
1466
|
+
|
1467
|
+
def sort_rows_move_nan(arr):
|
1468
|
+
# Handle edge cases where all values are NaN
|
1469
|
+
if np.all(np.isnan(arr)):
|
1470
|
+
return arr # Return unchanged if the entire array is NaN
|
1471
|
+
|
1472
|
+
# Replace NaNs with a temporary large value for sorting
|
1473
|
+
temp_value = (
|
1474
|
+
np.nanmax(arr[np.isfinite(arr)]) + 1 if np.any(np.isfinite(arr)) else np.inf
|
1475
|
+
)
|
1476
|
+
arr_no_nan = np.where(np.isnan(arr), temp_value, arr)
|
1477
|
+
|
1478
|
+
# Sort each row
|
1479
|
+
sorted_arr = np.sort(arr_no_nan, axis=1)
|
1480
|
+
|
1481
|
+
# Move NaNs to the end
|
1482
|
+
result_arr = np.where(sorted_arr == temp_value, np.nan, sorted_arr)
|
1483
|
+
|
1484
|
+
# Remove rows that contain only NaNs
|
1485
|
+
clean_arr = result_arr[~np.isnan(result_arr).all(axis=1)]
|
1486
|
+
|
1487
|
+
# Remove columns that contain only NaNs
|
1488
|
+
clean_arr_ = clean_arr[:, ~np.isnan(clean_arr).all(axis=0)]
|
1489
|
+
|
1490
|
+
return clean_arr_
|
1491
|
+
|
1492
|
+
|
1493
|
+
def df2array(data: pd.DataFrame, x, y, hue=None):
|
1494
|
+
if hue is None:
|
1495
|
+
a = []
|
1496
|
+
cat_x = data[x].unique().tolist()
|
1497
|
+
for i, x_ in enumerate(cat_x):
|
1498
|
+
new_ = data.loc[data[x] == x_, y].to_list()
|
1499
|
+
a = padcat(a, new_, axis=0)
|
1500
|
+
return sort_rows_move_nan(a.reshape(2**i, -1))
|
1501
|
+
else:
|
1502
|
+
a = []
|
1503
|
+
cat_x = data[x].unique().tolist()
|
1504
|
+
cat_hue = data[hue].unique().tolist()
|
1505
|
+
for i, x_ in enumerate(cat_x):
|
1506
|
+
for j, hue_ in enumerate(cat_hue):
|
1507
|
+
new_ = data.loc[(data[x] == x_) & (data[hue] == hue_), y].to_list()
|
1508
|
+
a = padcat(a, new_, axis=0)
|
1509
|
+
return sort_rows_move_nan(a.reshape(2 ** ((i + 1) * (j + 1)), -1))
|
@@ -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=
|
138
|
-
py2ls/netfinder.py,sha256=
|
139
|
-
py2ls/plot.py,sha256=
|
137
|
+
py2ls/ips.py,sha256=mBFTARM6Pvj5EaVRR05CXCBlyNcbX2JfMQWBjnxONjI,100773
|
138
|
+
py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
|
139
|
+
py2ls/plot.py,sha256=odZsLi4jG_WLULurpdGnWEyLC_RD_Yz2_EW-DqhJu98,54285
|
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.5.dist-info/METADATA,sha256=E0XmdaV6guqdnsCWF2XHqfkPHxrltAgElzNII6oWq8g,20017
|
146
|
+
py2ls-0.1.8.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
147
|
+
py2ls-0.1.8.5.dist-info/RECORD,,
|
File without changes
|