modusa 0.3.27__py3-none-any.whl → 0.3.28__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
@@ -7,8 +7,27 @@ import matplotlib.gridspec as gridspec
7
7
  from matplotlib.patches import Rectangle
8
8
  from mpl_toolkits.axes_grid1.inset_locator import inset_axes
9
9
 
10
+ # Helper for 2D plot
11
+ def _calculate_extent(x, y):
12
+ # Handle spacing safely
13
+ if len(x) > 1:
14
+ dx = x[1] - x[0]
15
+ else:
16
+ dx = 1 # Default spacing for single value
17
+ if len(y) > 1:
18
+ dy = y[1] - y[0]
19
+ else:
20
+ dy = 1 # Default spacing for single value
21
+
22
+ return [
23
+ x[0] - dx / 2,
24
+ x[-1] + dx / 2,
25
+ y[0] - dy / 2,
26
+ y[-1] + dy / 2
27
+ ]
28
+
10
29
  #======== 1D ===========
11
- def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylabel=None, title=None, legend=None):
30
+ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylabel=None, title=None, legend=None, show_grid=False):
12
31
  """
13
32
  Plots a 1D signal using matplotlib.
14
33
 
@@ -53,6 +72,9 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
53
72
  legend : list[str] | None
54
73
  - List of legend labels corresponding to each signal if plotting multiple lines.
55
74
  - Default: None
75
+ show_grid: bool
76
+ - If you want to show the grid.
77
+ - Default: False
56
78
 
57
79
  Returns
58
80
  -------
@@ -146,6 +168,10 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
146
168
  signal_ax.set_xlabel(xlabel)
147
169
  if ylabel is not None:
148
170
  signal_ax.set_ylabel(ylabel)
171
+
172
+ # Add grid to the plot
173
+ if show_grid is True:
174
+ signal_ax.grid(True, linestyle=':', linewidth=0.7, color='gray', alpha=0.7)
149
175
 
150
176
  # Remove the boundaries and ticks from an axis
151
177
  if ann is not None:
@@ -159,7 +185,7 @@ def plot1d(*args, ann=None, events=None, xlim=None, ylim=None, xlabel=None, ylab
159
185
  return fig
160
186
 
161
187
  #======== 2D ===========
162
- def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", Mlabel=None, xlabel=None, ylabel=None, title=None, legend=None, lm=False):
188
+ def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", Mlabel=None, xlabel=None, ylabel=None, title=None, legend=None, lm=False, show_grid=False):
163
189
  """
164
190
  Plots a 2D matrix (e.g., spectrogram or heatmap) with optional annotations and events.
165
191
 
@@ -213,6 +239,9 @@ def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", M
213
239
  - Adds a circular marker for the line.
214
240
  - Default: False
215
241
  - Useful to show the data points.
242
+ show_grid: bool
243
+ - If you want to show the grid.
244
+ - Default: False
216
245
 
217
246
  Returns
218
247
  -------
@@ -276,16 +305,12 @@ def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", M
276
305
  if len(signal) == 1: # It means that the axes were not passed
277
306
  y = np.arange(M.shape[0])
278
307
  x = np.arange(M.shape[1])
279
- dx = x[1] - x[0]
280
- dy = y[1] - y[0]
281
- extent=[x[0] - dx/2, x[-1] + dx/2, y[0] - dy/2, y[-1] + dy/2]
308
+ extent = _calculate_extent(x, y)
282
309
  im = signal_ax.imshow(M, aspect="auto", origin=origin, cmap="gray_r", extent=extent)
283
310
 
284
311
  elif len(signal) == 3: # It means that the axes were passed
285
312
  M, y, x = signal[0], signal[1], signal[2]
286
- dx = x[1] - x[0]
287
- dy = y[1] - y[0]
288
- extent=[x[0] - dx/2, x[-1] + dx/2, y[0] - dy/2, y[-1] + dy/2]
313
+ extent = _calculate_extent(x, y)
289
314
  im = signal_ax.imshow(M, aspect="auto", origin=origin, cmap="gray_r", extent=extent)
290
315
 
291
316
  # Add annotations
@@ -352,7 +377,10 @@ def plot2d(*args, ann=None, events=None, xlim=None, ylim=None, origin="lower", M
352
377
  signal_ax.set_xlabel(xlabel)
353
378
  if ylabel is not None:
354
379
  signal_ax.set_ylabel(ylabel)
355
-
380
+
381
+ # Add grid to the plot
382
+ if show_grid is True:
383
+ signal_ax.grid(True, linestyle=':', linewidth=0.7, color='gray', alpha=0.7)
356
384
 
357
385
  # Making annotation axis spines thicker
358
386
  if ann is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modusa
3
- Version: 0.3.27
3
+ Version: 0.3.28
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.27.dist-info/METADATA,sha256=YE2Sxy3pyXXbzkIjB5wqMme9ENn6-ZkqsbRiOn8Tfbw,1369
2
- modusa-0.3.27.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- modusa-0.3.27.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
- modusa-0.3.27.dist-info/licenses/LICENSE.md,sha256=JTaXAjx5awk76VArKCx5dUW8vmLEWsL_ZlR7-umaHbA,1078
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
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=Aacg-ezlMFdx_BK8yTOdsBBRQIGSwmWBmTwANr5TtHs,15388
50
+ modusa/tools/plotter.py,sha256=Pfj24jl-WHgdfPI-f4J_XLpMyed6OHkwAvtuIBKoAEw,16016
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.27.dist-info/RECORD,,
59
+ modusa-0.3.28.dist-info/RECORD,,