modusa 0.3.63__py3-none-any.whl → 0.3.65__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
@@ -43,14 +43,14 @@ class Fig:
43
43
  of annotations, events.
44
44
  """
45
45
 
46
- def __init__(self, arrangement="asm", xlim=None):
46
+ def __init__(self, arrangement="asm", xlim=None, width=16):
47
47
 
48
48
  self._xlim = xlim
49
49
  self._curr_row_idx = 1 # Starting from 1 because row 0 is reserved for reference subplot
50
50
  self._curr_color_idx = 0 # So that we have different color across all the subplots to avoid legend confusion
51
51
 
52
52
  # Subplot setup
53
- self._fig, self._axs = self._generate_subplots(arrangement) # This will fill in the all the above variables
53
+ self._fig, self._axs = self._generate_subplots(arrangement, width) # This will fill in the all the above variables
54
54
 
55
55
 
56
56
  def _get_curr_row(self):
@@ -96,12 +96,13 @@ class Fig:
96
96
  return [x[0] - dx / 2, x[-1] + dx / 2, y[-1] + dy / 2, y[0] - dy / 2]
97
97
 
98
98
 
99
- def _generate_subplots(self, arrangement):
99
+ def _generate_subplots(self, arrangement, width):
100
100
  """
101
101
  Generate subplots based on the configuration.
102
102
  """
103
103
 
104
104
  xlim = self._xlim
105
+ fig_width = width
105
106
 
106
107
  n_aux_sp = arrangement.count("a")
107
108
  n_signal_sp = arrangement.count("s")
@@ -126,7 +127,7 @@ class Fig:
126
127
  fig_height = height["r"] + (n_aux_sp * height["a"]) + (n_signal_sp * height["s"]) + (n_matrix_sp * height["m"])
127
128
 
128
129
  # Create figure and axs
129
- fig, axs = plt.subplots(n_sp, 2, figsize=(16, fig_height), height_ratios=height_ratios, width_ratios=[1, cbar_width])
130
+ fig, axs = plt.subplots(n_sp, 2, figsize=(fig_width, fig_height), height_ratios=height_ratios, width_ratios=[1, cbar_width])
130
131
 
131
132
  for i, char in enumerate(arrangement): # For each of the subplots, we modify the layout accordingly
132
133
  if char == "r":
@@ -156,7 +157,7 @@ class Fig:
156
157
 
157
158
  return fig, axs
158
159
 
159
- def add_signal(self, y, x=None, c=None, ls=None, lw=None, m=None, ms=3, label=None, ylabel=None, ylim=None, ax=None):
160
+ def add_signal(self, y, x=None, c=None, ls=None, lw=None, m=None, ms=3, label=None, ylabel=None, ylim=None, yticks=None, yticklabels=None, xticks=None, xticklabels=None, ax=None):
160
161
  """
161
162
  Add signal to the figure.
162
163
 
@@ -192,6 +193,14 @@ class Fig:
192
193
  ylim: tuple
193
194
  - y-lim for the plot.
194
195
  - Default: None
196
+ yticks: Arraylike
197
+ - Positions at which to place y-axis ticks.
198
+ yticklabels : list of str, optional
199
+ - Labels corresponding to `yticks`. Must be the same length as `yticks`.
200
+ xticks: Arraylike
201
+ - Positions at which to place x-axis ticks.
202
+ xticklabels : list of str, optional
203
+ - Labels corresponding to `xticks`. Must be the same length as `xticks`.
195
204
  ax: int
196
205
  - Which specific axis to plot (1, 2, 3, ...)
197
206
  - None
@@ -203,17 +212,32 @@ class Fig:
203
212
 
204
213
  curr_row = self._get_curr_row() if ax is None else self._axs[ax]
205
214
 
206
- if x is None: x = np.arange(y.size)
215
+ if x is None:
216
+ x = np.arange(y.size)
207
217
 
208
- if c is None: c = self._get_new_color()
218
+ if c is None:
219
+ c = self._get_new_color()
209
220
 
210
221
  curr_row[0].plot(x, y, color=c, linestyle=ls, linewidth=lw, marker=m, markersize=ms, label=label)
211
222
 
212
- if ylabel is not None: curr_row[0].set_ylabel(ylabel)
223
+ if ylabel is not None:
224
+ curr_row[0].set_ylabel(ylabel)
225
+
226
+ if ylim is not None:
227
+ curr_row[0].set_ylim(ylim)
213
228
 
214
- if ylim is not None: curr_row[0].set_ylim(ylim)
229
+ if yticks is not None:
230
+ curr_row[0].set_yticks(yticks)
231
+ if yticklabels is not None:
232
+ curr_row[0].set_yticklabels(yticklabels)
233
+
234
+ if xticks is not None:
235
+ curr_row[0].set_xticks(xticks)
236
+ if xticklabels is not None:
237
+ curr_row[0].set_xticklabels(xticklabels)
238
+
215
239
 
216
- def add_matrix(self, M, y=None, x=None, c="gray_r", o="upper", label=None, ylabel=None, ylim=None, cbar=True, ax=None):
240
+ def add_matrix(self, M, y=None, x=None, c="gray_r", o="upper", label=None, ylabel=None, ylim=None, yticks=None, yticklabels=None, xticks=None, xticklabels=None, cbar=True, ax=None):
217
241
  """
218
242
  Add matrix to the figure.
219
243
 
@@ -242,6 +266,14 @@ class Fig:
242
266
  ylim: tuple
243
267
  - y-lim for the plot.
244
268
  - Default: None
269
+ yticks: Arraylike
270
+ - Positions at which to place y-axis ticks.
271
+ yticklabels : list of str, optional
272
+ - Labels corresponding to `yticks`. Must be the same length as `yticks`.
273
+ xticks: Arraylike
274
+ - Positions at which to place x-axis ticks.
275
+ xticklabels : list of str, optional
276
+ - Labels corresponding to `xticks`. Must be the same length as `xticks`.
245
277
  cbar: bool
246
278
  - Show colorbar
247
279
  - Default: True
@@ -274,6 +306,16 @@ class Fig:
274
306
  cbar = plt.colorbar(im, cax=curr_row[1])
275
307
  if label is not None:
276
308
  cbar.set_label(label, labelpad=5)
309
+
310
+ if yticks is not None:
311
+ curr_row[0].set_yticks(yticks)
312
+ if yticklabels is not None:
313
+ curr_row[0].set_yticklabels(yticklabels)
314
+
315
+ if xticks is not None:
316
+ curr_row[0].set_xticks(xticks)
317
+ if xticklabels is not None:
318
+ curr_row[0].set_xticklabels(xticklabels)
277
319
 
278
320
 
279
321
  def add_events(self, events, c=None, ls=None, lw=None, label=None, ax=None):
@@ -325,7 +367,7 @@ class Fig:
325
367
  else:
326
368
  curr_row[0].axvline(x=event, color=c, linestyle=ls, linewidth=lw)
327
369
 
328
- def add_annotation(self, ann, label=None, patterns=None, ax=None, ylim=(0, 1)):
370
+ def add_annotation(self, ann, label=None, patterns=None, ax=None, ylim=(0, 1), text_loc="middle"):
329
371
  """
330
372
  Add annotation to the figure.
331
373
 
@@ -348,6 +390,9 @@ class Fig:
348
390
  ylim: tuple[number, number]
349
391
  - Y-limit for the annotation.
350
392
  - Default: (0, 1)
393
+ text_loc: str
394
+ - Location of text relative to the box. (b for bottom, m for middle, t for top)
395
+ - Default: "middle"
351
396
  Returns
352
397
  -------
353
398
  None
@@ -373,6 +418,14 @@ class Fig:
373
418
 
374
419
  colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
375
420
 
421
+ # Text Location
422
+ if text_loc == "b":
423
+ text_yloc = ylim[0] + 0.1 * (ylim[1] - ylim[0])
424
+ elif text_loc == "t":
425
+ text_yloc = ylim[1] - 0.1 * (ylim[1] - ylim[0])
426
+ else:
427
+ text_yloc = (ylim[1] + ylim[0]) / 2
428
+
376
429
  for i, (start, end, tag, group) in enumerate(ann_copy):
377
430
  # We make sure that we only plot annotation that are within the x range of the current view
378
431
  if xlim is not None:
@@ -382,6 +435,7 @@ class Fig:
382
435
  # Clip boundaries to xlim
383
436
  start = max(start, xlim[0])
384
437
  end = min(end, xlim[1])
438
+
385
439
 
386
440
  if group is not None:
387
441
  box_color = colors[group]
@@ -393,7 +447,7 @@ class Fig:
393
447
  curr_row[0].add_patch(rect)
394
448
 
395
449
  text_obj = curr_row[0].text(
396
- (start + end) / 2, (ylim[1] + ylim[0]) / 2, tag,
450
+ (start + end) / 2, text_yloc, tag,
397
451
  ha='center', va='center',
398
452
  fontsize=10, color="black", fontweight='bold', zorder=10, clip_on=True
399
453
  )
@@ -410,7 +464,7 @@ class Fig:
410
464
  curr_row[0].add_patch(rect)
411
465
 
412
466
  text_obj = curr_row[0].text(
413
- (start + end) / 2, (ylim[1] + ylim[0]) / 2, tag,
467
+ (start + end) / 2, text_yloc, tag,
414
468
  ha='center', va='center',
415
469
  fontsize=10, color="black", fontweight='bold', zorder=10, clip_on=True
416
470
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modusa
3
- Version: 0.3.63
3
+ Version: 0.3.65
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.63.dist-info/METADATA,sha256=tfaSBaX_xBshoc5yyA3hN2zSOWxJ4URB3Dce_Mjd5pE,1436
2
- modusa-0.3.63.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- modusa-0.3.63.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
- modusa-0.3.63.dist-info/licenses/LICENSE.md,sha256=JTaXAjx5awk76VArKCx5dUW8vmLEWsL_ZlR7-umaHbA,1078
1
+ modusa-0.3.65.dist-info/METADATA,sha256=Qk9jra_1KDD-nWaTPhQQp0jZh7_DVx1H-p-DenRis5I,1436
2
+ modusa-0.3.65.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ modusa-0.3.65.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
+ modusa-0.3.65.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=RMIKAZZ27w1oh2UFMJvZQtQ-SluIQsac_3mSK_LaM30,277
7
7
  modusa/config.py,sha256=bTqK4t00FZqERVITrxW_q284aDDJAa9aMSfFknfR-oU,280
@@ -50,7 +50,7 @@ modusa/tools/audio_player.py,sha256=GP04TWW4jBwQBjANkfR_cJtEy7cIhvbu8RTwnf9hD6E,
50
50
  modusa/tools/audio_recorder.py,sha256=d2fVt0Sd2tlBdb2WlUs60K4N23zuxM3KUpQqX0ifPi8,2769
51
51
  modusa/tools/base.py,sha256=C0ESJ0mIfjjRlAkRbSetNtMoOfS6IrHBjexRp3l_Mh4,1293
52
52
  modusa/tools/math_ops.py,sha256=ZZ7U4DgqT7cOeE7_Lzi_Qq-48WYfwR9_osbZwTmE9eg,8690
53
- modusa/tools/plotter.py,sha256=S2kIUvyZ1NvhLjEClNV09PyfzZd6fOjaZ8-7NLqSlCw,18076
53
+ modusa/tools/plotter.py,sha256=cNXnT8UMOyAC0sSVDCPWERqKx6MBWvs5ERf6zvY9BX4,19886
54
54
  modusa/tools/youtube_downloader.py,sha256=hB_X8-7nOHXOlxg6vv3wyhBLoAsWyomrULP6_uCQL7s,1698
55
55
  modusa/utils/.DS_Store,sha256=nLXMwF7QJNuglLI_Gk74F7vl5Dyus2Wd74Mgowijmdo,6148
56
56
  modusa/utils/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
@@ -59,4 +59,4 @@ modusa/utils/excp.py,sha256=L9vhaGjKpv9viJYdmC9n5ndmk2GVbUBuFyZyhAQZmWY,906
59
59
  modusa/utils/logger.py,sha256=K0rsnObeNKCxlNeSnVnJeRhgfmob6riB2uyU7h3dDmA,571
60
60
  modusa/utils/np_func_cat.py,sha256=TyIFgRc6bARRMDnZxlVURO5Z0I-GWhxRONYyIv-Vwxs,1007
61
61
  modusa/utils/plot.py,sha256=s_vNdxvKfwxEngvJPgrF1PcmxZNnNaaXPViHWjyjJ-c,5335
62
- modusa-0.3.63.dist-info/RECORD,,
62
+ modusa-0.3.65.dist-info/RECORD,,