modusa 0.3.28__py3-none-any.whl → 0.3.29__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.
modusa/tools/plotter.py CHANGED
@@ -85,6 +85,7 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
85
85
  for arg in args:
86
86
  if len(arg) not in [1, 2]: # 1 if it just provides values, 2 if it provided axis as well
87
87
  raise ValueError(f"1D signal needs to have max 2 arrays (y, x) or simply (y, )")
88
+
88
89
  if isinstance(legend, str): legend = (legend, )
89
90
 
90
91
  if legend is not None:
@@ -111,10 +112,11 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
111
112
  for i, signal in enumerate(args):
112
113
  if len(signal) == 1:
113
114
  y = signal[0]
115
+ x = np.arange(y.size)
114
116
  if legend is not None:
115
- signal_ax.plot(y, label=legend[i])
117
+ signal_ax.plot(x, y, label=legend[i])
116
118
  else:
117
- signal_ax.plot(y)
119
+ signal_ax.plot(x, y)
118
120
  elif len(signal) == 2:
119
121
  y, x = signal[0], signal[1]
120
122
  if legend is not None:
@@ -124,14 +126,19 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
124
126
 
125
127
  # Add annotations
126
128
  if ann is not None:
127
- annotation_ax.set_ylim(0, 1)
129
+ annotation_ax.set_ylim(0, 1) # For consistent layout
130
+ # Determine visible x-range
131
+ x_view_min = xlim[0] if xlim is not None else np.min(x)
132
+ x_view_max = xlim[1] if xlim is not None else np.max(x)
133
+
128
134
  for i, (start, end, tag) in enumerate(ann):
129
- if xlim is not None:
130
- if end < xlim[0] or start > xlim[1]:
131
- continue # Skip out-of-view regions
132
- # Clip boundaries to xlim
133
- start = max(start, xlim[0])
134
- end = min(end, xlim[1])
135
+ # We make sure that we only plot annotation that are within the x range of the current view
136
+ if start >= x_view_max or end <= x_view_min:
137
+ continue
138
+
139
+ # Clip boundaries to xlim
140
+ start = max(start, x_view_min)
141
+ end = min(end, x_view_max)
135
142
 
136
143
  color = colors[i % len(colors)]
137
144
  width = end - start
@@ -315,14 +322,19 @@ def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", M
315
322
 
316
323
  # Add annotations
317
324
  if ann is not None:
318
- annotation_ax.set_ylim(0, 1)
325
+ annotation_ax.set_ylim(0, 1) # For consistent layout
326
+ # Determine visible x-range
327
+ x_view_min = xlim[0] if xlim is not None else np.min(x)
328
+ x_view_max = xlim[1] if xlim is not None else np.max(x)
329
+
319
330
  for i, (start, end, tag) in enumerate(ann):
320
- if xlim is not None:
321
- if end < xlim[0] or start > xlim[1]:
322
- continue # Skip out-of-view regions
323
- # Clip boundaries to xlim
324
- start = max(start, xlim[0])
325
- end = min(end, xlim[1])
331
+ # We make sure that we only plot annotation that are within the x range of the current view
332
+ if start >= x_view_max or end <= x_view_min:
333
+ continue
334
+
335
+ # Clip boundaries to xlim
336
+ start = max(start, x_view_min)
337
+ end = min(end, x_view_max)
326
338
 
327
339
  color = colors[i % len(colors)]
328
340
  width = end - start
@@ -479,36 +491,40 @@ def plot_dist(*args, ann=None, xlim=None, ylim=None, ylabel=None, xlabel=None, t
479
491
  kde = gaussian_kde(data)
480
492
 
481
493
  # Create points to evaluate KDE
482
- x_vals = np.linspace(min(data), max(data), npoints)
483
- y_vals = kde(x_vals)
494
+ x = np.linspace(min(data), max(data), npoints)
495
+ y = kde(x)
484
496
 
485
497
  if legend is not None:
486
- dist_ax.plot(x_vals, y_vals, color=colors[i], label=legend[i])
498
+ dist_ax.plot(x, y, color=colors[i], label=legend[i])
487
499
  if show_hist is True:
488
500
  dist_ax.hist(data, bins=bins, density=True, alpha=0.3, facecolor=colors[i], edgecolor='black', label=legend[i])
489
501
  else:
490
- dist_ax.plot(x_vals, y_vals, color=colors[i])
502
+ dist_ax.plot(x, y, color=colors[i])
491
503
  if show_hist is True:
492
504
  dist_ax.hist(data, bins=bins, density=True, alpha=0.3, facecolor=colors[i], edgecolor='black')
493
505
 
494
506
  # Add annotations
495
507
  if ann is not None:
496
- annotation_ax.set_ylim(0, 1)
497
- for i, (start, end, tag) in enumerate(ann):
498
- if xlim is not None:
499
- if end < xlim[0] or start > xlim[1]:
500
- continue # Skip out-of-view regions
501
- # Clip boundaries to xlim
502
- start = max(start, xlim[0])
503
- end = min(end, xlim[1])
504
-
505
- color = colors[i % len(colors)]
506
- width = end - start
507
- rect = Rectangle((start, 0), width, 1, color=color, alpha=0.7)
508
- annotation_ax.add_patch(rect)
508
+ annotation_ax.set_ylim(0, 1) # For consistent layout
509
+ # Determine visible x-range
510
+ x_view_min = xlim[0] if xlim is not None else np.min(x)
511
+ x_view_max = xlim[1] if xlim is not None else np.max(x)
512
+ for i, (start, end, tag) in enumerate(ann):
513
+ # We make sure that we only plot annotation that are within the x range of the current view
514
+ if start >= x_view_max or end <= x_view_min:
515
+ continue
516
+
517
+ # Clip boundaries to xlim
518
+ start = max(start, x_view_min)
519
+ end = min(end, x_view_max)
509
520
 
510
- text_obj = annotation_ax.text((start + end) / 2, 0.5, tag, ha='center', va='center', fontsize=10, color='white', fontweight='bold', zorder=10, clip_on=True)
511
- text_obj.set_clip_path(rect)
521
+ color = colors[i % len(colors)]
522
+ width = end - start
523
+ rect = Rectangle((start, 0), width, 1, color=color, alpha=0.7)
524
+ annotation_ax.add_patch(rect)
525
+
526
+ text_obj = annotation_ax.text((start + end) / 2, 0.5, tag, ha='center', va='center', fontsize=10, color='white', fontweight='bold', zorder=10, clip_on=True)
527
+ text_obj.set_clip_path(rect)
512
528
 
513
529
  # Add legend
514
530
  if legend is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modusa
3
- Version: 0.3.28
3
+ Version: 0.3.29
4
4
  Summary: A modular signal analysis python library.
5
5
  Author-Email: Ankit Anand <ankit0.anand0@gmail.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- modusa-0.3.28.dist-info/METADATA,sha256=wNR4dM9jMye2V4s7H9zhtD6k9w6B8kUdlzGQdxbINvc,1369
2
- modusa-0.3.28.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- modusa-0.3.28.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
- modusa-0.3.28.dist-info/licenses/LICENSE.md,sha256=JTaXAjx5awk76VArKCx5dUW8vmLEWsL_ZlR7-umaHbA,1078
1
+ modusa-0.3.29.dist-info/METADATA,sha256=vQcmNOAAZljrLUb7gHJoqvkTgSNsdzhzxxu0vcM5YJo,1369
2
+ modusa-0.3.29.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ modusa-0.3.29.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
+ modusa-0.3.29.dist-info/licenses/LICENSE.md,sha256=JTaXAjx5awk76VArKCx5dUW8vmLEWsL_ZlR7-umaHbA,1078
5
5
  modusa/.DS_Store,sha256=_gm6qJREwfMi8dE7n5S89_RG46u5t3xHyD-smNhtNoM,6148
6
6
  modusa/__init__.py,sha256=uq6kORFFAODiCMGmOLWO0shE8-dVFWf5gmV8wxekmnk,280
7
7
  modusa/config.py,sha256=bTqK4t00FZqERVITrxW_q284aDDJAa9aMSfFknfR-oU,280
@@ -47,7 +47,7 @@ modusa/tools/audio_loader.py,sha256=DrCzq0pdiQrUDIG-deLJGcu8EaylO5yRtwT4lr8WSf8,
47
47
  modusa/tools/audio_player.py,sha256=GP04TWW4jBwQBjANkfR_cJtEy7cIhvbu8RTwnf9hD6E,2817
48
48
  modusa/tools/base.py,sha256=C0ESJ0mIfjjRlAkRbSetNtMoOfS6IrHBjexRp3l_Mh4,1293
49
49
  modusa/tools/math_ops.py,sha256=ZZ7U4DgqT7cOeE7_Lzi_Qq-48WYfwR9_osbZwTmE9eg,8690
50
- modusa/tools/plotter.py,sha256=Pfj24jl-WHgdfPI-f4J_XLpMyed6OHkwAvtuIBKoAEw,16016
50
+ modusa/tools/plotter.py,sha256=A559FRQcBCVfVKYBq90b-YyZjwGayTCf5Gsn1Zxc1k8,16674
51
51
  modusa/tools/youtube_downloader.py,sha256=hB_X8-7nOHXOlxg6vv3wyhBLoAsWyomrULP6_uCQL7s,1698
52
52
  modusa/utils/.DS_Store,sha256=nLXMwF7QJNuglLI_Gk74F7vl5Dyus2Wd74Mgowijmdo,6148
53
53
  modusa/utils/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
@@ -56,4 +56,4 @@ modusa/utils/excp.py,sha256=L9vhaGjKpv9viJYdmC9n5ndmk2GVbUBuFyZyhAQZmWY,906
56
56
  modusa/utils/logger.py,sha256=K0rsnObeNKCxlNeSnVnJeRhgfmob6riB2uyU7h3dDmA,571
57
57
  modusa/utils/np_func_cat.py,sha256=TyIFgRc6bARRMDnZxlVURO5Z0I-GWhxRONYyIv-Vwxs,1007
58
58
  modusa/utils/plot.py,sha256=s_vNdxvKfwxEngvJPgrF1PcmxZNnNaaXPViHWjyjJ-c,5335
59
- modusa-0.3.28.dist-info/RECORD,,
59
+ modusa-0.3.29.dist-info/RECORD,,