py2ls 0.1.8.8__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
- from .plot import get_color
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
@@ -8,6 +8,7 @@ import matplotlib
8
8
  import matplotlib.ticker as tck
9
9
  from cycler import cycler
10
10
  import logging
11
+ from .ips import fsave
11
12
 
12
13
  # Suppress INFO messages from fontTools
13
14
  logging.getLogger("fontTools").setLevel(logging.WARNING)
@@ -57,7 +58,7 @@ def catplot(data, *args, **kwargs):
57
58
  xloc, opt_e["loc"], opt_e["x_width"], data.shape[0]
58
59
  )
59
60
  error_positions = np.nanmean(error_positions, axis=0)
60
- errors = np.nanstd(data, axis=0)
61
+ errors = np.nanstd(data, axis=0, ddof=1)
61
62
  if opt_e["error"] == "sem":
62
63
  errors /= np.sqrt(np.sum(~np.isnan(data), axis=0))
63
64
 
@@ -212,6 +213,9 @@ def catplot(data, *args, **kwargs):
212
213
  color=bx_opt["MeanLineColor"],
213
214
  linewidth=bx_opt["MeanLineWidth"],
214
215
  )
216
+ # MeanLine or MedianLine only keep only one
217
+ if bx_opt["MeanLine"]: # MeanLine has priority
218
+ bx_opt["MedianLine"] = False
215
219
  bxp = ax.boxplot(
216
220
  data,
217
221
  positions=X_bx,
@@ -231,6 +235,9 @@ def catplot(data, *args, **kwargs):
231
235
  widths=bx_opt["x_width"],
232
236
  label=label,
233
237
  )
238
+ if not bx_opt["MedianLine"]:
239
+ for median in bxp["medians"]:
240
+ median.set_visible(False)
234
241
 
235
242
  if bx_opt["BoxLineWidth"] < 0.1:
236
243
  bx_opt["EdgeColor"] = "none"
@@ -471,12 +478,15 @@ def catplot(data, *args, **kwargs):
471
478
  xticks = generate_xticks_with_gap(x_len, hue_len)
472
479
  default_x_width = 0.85
473
480
  legend_hue = df[hue].unique().tolist()
481
+ default_colors = get_color(hue_len)
474
482
  else:
475
483
  for i in df[x].unique().tolist():
476
484
  xticklabels.append(i)
477
- xticks = np.arange(1, len(xticklabels) + 1)
485
+ xticks = np.arange(1, len(xticklabels) + 1).tolist()
478
486
  legend_hue = xticklabels
487
+ default_colors = get_color(len(xticklabels))
479
488
  default_x_width = 0.5
489
+
480
490
  # when the xticklabels are too long, rotate the labels a bit
481
491
 
482
492
  xangle = 30 if max([len(i) for i in xticklabels]) > 5 else 0
@@ -498,7 +508,7 @@ def catplot(data, *args, **kwargs):
498
508
  "xangle": xangle,
499
509
  }
500
510
  else:
501
- xticks = np.arange(1, data.shape[1] + 1)
511
+ xticks = np.arange(1, data.shape[1] + 1).tolist()
502
512
  default_x_width = 0.5
503
513
  xangle = 0
504
514
 
@@ -507,27 +517,12 @@ def catplot(data, *args, **kwargs):
507
517
  ax = kwargs.get("ax", None)
508
518
  if "ax" not in locals() or ax is None:
509
519
  ax = plt.gca()
510
-
511
- default_colors = (
512
- np.array(
513
- [
514
- [0, 0, 0],
515
- [234, 37, 46],
516
- [0, 154, 222],
517
- [175, 89, 186],
518
- [255, 198, 37],
519
- [242, 133, 34],
520
- ]
521
- )
522
- / 255.0
523
- )
524
-
525
520
  opt.setdefault("c", default_colors)
526
- if len(opt["c"]) < data.shape[1]:
527
- additional_colors = plt.cm.winter(
528
- np.linspace(0, 1, data.shape[1] - len(opt["c"]))
529
- )
530
- opt["c"] = np.vstack([opt["c"], additional_colors[:, :3]])
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]])
531
526
 
532
527
  opt.setdefault("loc", {})
533
528
  opt["loc"].setdefault("go", 0)
@@ -545,7 +540,7 @@ def catplot(data, *args, **kwargs):
545
540
  opt["b"].setdefault("go", 1)
546
541
  opt["b"].setdefault("loc", "c")
547
542
  opt["b"].setdefault("FaceColor", opt["c"])
548
- opt["b"].setdefault("FaceAlpha", 0.65)
543
+ opt["b"].setdefault("FaceAlpha", 1)
549
544
  opt["b"].setdefault("EdgeColor", "k")
550
545
  opt["b"].setdefault("EdgeAlpha", 1)
551
546
  opt["b"].setdefault("LineStyle", "-")
@@ -576,13 +571,13 @@ def catplot(data, *args, **kwargs):
576
571
  opt.setdefault("s", {})
577
572
  opt["s"].setdefault("go", 1)
578
573
  opt["s"].setdefault("loc", "r")
579
- opt["s"].setdefault("FaceColor", opt["c"])
574
+ opt["s"].setdefault("FaceColor", "w")
580
575
  opt["s"].setdefault("cmap", None)
581
576
  opt["s"].setdefault("FaceAlpha", 1)
582
577
  opt["s"].setdefault("x_width", opt["b"]["x_width"] / 5)
583
578
  opt["s"].setdefault("Marker", "o")
584
- opt["s"].setdefault("MarkerSize", 10)
585
- opt["s"].setdefault("LineWidth", 0.5)
579
+ opt["s"].setdefault("MarkerSize", 15)
580
+ opt["s"].setdefault("LineWidth", 0.8)
586
581
  opt["s"].setdefault("MarkerEdgeColor", "k")
587
582
 
588
583
  opt.setdefault("l", {})
@@ -597,7 +592,7 @@ def catplot(data, *args, **kwargs):
597
592
  opt["bx"].setdefault("loc", "r")
598
593
  opt["bx"].setdefault("FaceColor", opt["c"])
599
594
  opt["bx"].setdefault("EdgeColor", "k")
600
- opt["bx"].setdefault("FaceAlpha", 0.7)
595
+ opt["bx"].setdefault("FaceAlpha", 0.85)
601
596
  opt["bx"].setdefault("EdgeAlpha", 1)
602
597
  opt["bx"].setdefault("LineStyle", "-")
603
598
  opt["bx"].setdefault("x_width", 0.2)
@@ -620,6 +615,7 @@ def catplot(data, *args, **kwargs):
620
615
  opt["bx"].setdefault("CapLineColor", "k")
621
616
  opt["bx"].setdefault("CapLineWidth", 0.5)
622
617
  opt["bx"].setdefault("CapSize", 0.2)
618
+ opt["bx"].setdefault("MedianLine", True)
623
619
  opt["bx"].setdefault("MedianLineStyle", "-")
624
620
  opt["bx"].setdefault("MedianStyle", "line")
625
621
  opt["bx"].setdefault("MedianLineColor", "k")
@@ -705,7 +701,13 @@ def catplot(data, *args, **kwargs):
705
701
 
706
702
  if kw_figsets is not None:
707
703
  figsets(ax=ax, **kw_figsets)
708
- return ax
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
709
711
 
710
712
 
711
713
  def get_cmap():
@@ -1356,14 +1358,16 @@ def stdshade(ax=None, *args, **kwargs):
1356
1358
  yMean = np.nanmean(y, axis=0)
1357
1359
  if paraStdSem == "sem":
1358
1360
  if smth > 1:
1359
- wings = savgol_filter(np.nanstd(y, axis=0) / np.sqrt(y.shape[0]), smth, 1)
1361
+ wings = savgol_filter(
1362
+ np.nanstd(y, axis=0, ddof=1) / np.sqrt(y.shape[0]), smth, 1
1363
+ )
1360
1364
  else:
1361
- 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])
1362
1366
  elif paraStdSem == "std":
1363
1367
  if smth > 1:
1364
- wings = savgol_filter(np.nanstd(y, axis=0), smth, 1)
1368
+ wings = savgol_filter(np.nanstd(y, axis=0, ddof=1), smth, 1)
1365
1369
  else:
1366
- wings = np.nanstd(y, axis=0)
1370
+ wings = np.nanstd(y, axis=0, ddof=1)
1367
1371
 
1368
1372
  # fill_kws = kwargs.get('fill_kws', {})
1369
1373
  # line_kws = kwargs.get('line_kws', {})
@@ -1668,6 +1672,6 @@ def generate_xticks_with_gap(x_len, hue_len):
1668
1672
  for i in range(max(x_len, hue_len), 0, -1) # i iterates from 3 to 1
1669
1673
  ]
1670
1674
  concatenated_array = np.concatenate(arrays)
1671
- positive_array = concatenated_array[concatenated_array > 0]
1675
+ positive_array = concatenated_array[concatenated_array > 0].tolist()
1672
1676
 
1673
1677
  return positive_array
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.8.8
3
+ Version: 0.1.8.9
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -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=6eNvNwaCDj2jyjter7VPL9oEGB2jS4ge9mSgiIrvZfo,100788
137
+ py2ls/ips.py,sha256=N7MdOCgJXDQu73YkJQTtDN3RSntzXX7V0MOJ1NYBLEk,100572
138
138
  py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
139
- py2ls/plot.py,sha256=E6cV26ixVa8HFYTsTvaEtc-CgLYvaA7OhPg6S0eBZ2M,62740
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.8.dist-info/METADATA,sha256=tnUzLUWK94WS_DVJ1Jxcn_fRFrQRktuceHW0WMRfS5g,20017
146
- py2ls-0.1.8.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.8.8.dist-info/RECORD,,
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,,