modusa 0.3.64__py3-none-any.whl → 0.3.66__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
@@ -41,16 +41,47 @@ class Fig:
41
41
  A utility class that provides easy-to-use API for
42
42
  plotting 1D/2D signals along with clean representations
43
43
  of annotations, events.
44
+
45
+ Parameters
46
+ ----------
47
+ arrangement: str
48
+ - Arrangement of the subplots you want in the figure.
49
+ - "a" for aux plot which is good for adding annotations and events onto.
50
+ - "s" for signal plot which is good for 1D array.
51
+ - "m" for matrix plot which is good for 2D array.
52
+ - E.g., "asm" or "aasm" or "saams", ...
53
+ - Default: "asm"
54
+ xlim: tuple[number, number] | None
55
+ - Since all the subplots share x-axis, we set the x limit while creating the figure.
56
+ - Default: None
57
+ width: number
58
+ - Width of the figure
59
+ - Default: 16
60
+ dark_mode: bool
61
+ - Do you want dark mode?
62
+ - Default: True
44
63
  """
45
64
 
46
- def __init__(self, arrangement="asm", xlim=None):
65
+ def __init__(self, arrangement="asm", xlim=None, width=16, dark_mode=True):
66
+
67
+ if dark_mode:
68
+ plt.style.use("dark_background")
69
+ else: # We do not reset to default as it changes other params leading to unexpected behaviour
70
+ color_keys = [
71
+ "axes.facecolor", "axes.edgecolor", "axes.labelcolor",
72
+ "xtick.color", "ytick.color", "text.color",
73
+ "figure.facecolor", "figure.edgecolor",
74
+ "legend.facecolor", "legend.edgecolor"
75
+ ]
76
+ for k in color_keys:
77
+ mpl.rcParams[k] = mpl.rcParamsDefault[k]
47
78
 
48
79
  self._xlim = xlim
49
80
  self._curr_row_idx = 1 # Starting from 1 because row 0 is reserved for reference subplot
50
81
  self._curr_color_idx = 0 # So that we have different color across all the subplots to avoid legend confusion
51
82
 
52
83
  # Subplot setup
53
- self._fig, self._axs = self._generate_subplots(arrangement) # This will fill in the all the above variables
84
+ self._fig, self._axs = self._generate_subplots(arrangement, width) # This will fill in the all the above variables
54
85
 
55
86
 
56
87
  def _get_curr_row(self):
@@ -96,12 +127,13 @@ class Fig:
96
127
  return [x[0] - dx / 2, x[-1] + dx / 2, y[-1] + dy / 2, y[0] - dy / 2]
97
128
 
98
129
 
99
- def _generate_subplots(self, arrangement):
130
+ def _generate_subplots(self, arrangement, width):
100
131
  """
101
132
  Generate subplots based on the configuration.
102
133
  """
103
134
 
104
135
  xlim = self._xlim
136
+ fig_width = width
105
137
 
106
138
  n_aux_sp = arrangement.count("a")
107
139
  n_signal_sp = arrangement.count("s")
@@ -126,7 +158,7 @@ class Fig:
126
158
  fig_height = height["r"] + (n_aux_sp * height["a"]) + (n_signal_sp * height["s"]) + (n_matrix_sp * height["m"])
127
159
 
128
160
  # 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])
161
+ fig, axs = plt.subplots(n_sp, 2, figsize=(fig_width, fig_height), height_ratios=height_ratios, width_ratios=[1, cbar_width])
130
162
 
131
163
  for i, char in enumerate(arrangement): # For each of the subplots, we modify the layout accordingly
132
164
  if char == "r":
@@ -156,7 +188,7 @@ class Fig:
156
188
 
157
189
  return fig, axs
158
190
 
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):
191
+ 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
192
  """
161
193
  Add signal to the figure.
162
194
 
@@ -192,6 +224,14 @@ class Fig:
192
224
  ylim: tuple
193
225
  - y-lim for the plot.
194
226
  - Default: None
227
+ yticks: Arraylike
228
+ - Positions at which to place y-axis ticks.
229
+ yticklabels : list of str, optional
230
+ - Labels corresponding to `yticks`. Must be the same length as `yticks`.
231
+ xticks: Arraylike
232
+ - Positions at which to place x-axis ticks.
233
+ xticklabels : list of str, optional
234
+ - Labels corresponding to `xticks`. Must be the same length as `xticks`.
195
235
  ax: int
196
236
  - Which specific axis to plot (1, 2, 3, ...)
197
237
  - None
@@ -203,17 +243,32 @@ class Fig:
203
243
 
204
244
  curr_row = self._get_curr_row() if ax is None else self._axs[ax]
205
245
 
206
- if x is None: x = np.arange(y.size)
246
+ if x is None:
247
+ x = np.arange(y.size)
207
248
 
208
- if c is None: c = self._get_new_color()
249
+ if c is None:
250
+ c = self._get_new_color()
209
251
 
210
252
  curr_row[0].plot(x, y, color=c, linestyle=ls, linewidth=lw, marker=m, markersize=ms, label=label)
211
253
 
212
- if ylabel is not None: curr_row[0].set_ylabel(ylabel)
254
+ if ylabel is not None:
255
+ curr_row[0].set_ylabel(ylabel)
256
+
257
+ if ylim is not None:
258
+ curr_row[0].set_ylim(ylim)
213
259
 
214
- if ylim is not None: curr_row[0].set_ylim(ylim)
260
+ if yticks is not None:
261
+ curr_row[0].set_yticks(yticks)
262
+ if yticklabels is not None:
263
+ curr_row[0].set_yticklabels(yticklabels)
264
+
265
+ if xticks is not None:
266
+ curr_row[0].set_xticks(xticks)
267
+ if xticklabels is not None:
268
+ curr_row[0].set_xticklabels(xticklabels)
269
+
215
270
 
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):
271
+ 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
272
  """
218
273
  Add matrix to the figure.
219
274
 
@@ -242,6 +297,14 @@ class Fig:
242
297
  ylim: tuple
243
298
  - y-lim for the plot.
244
299
  - Default: None
300
+ yticks: Arraylike
301
+ - Positions at which to place y-axis ticks.
302
+ yticklabels : list of str, optional
303
+ - Labels corresponding to `yticks`. Must be the same length as `yticks`.
304
+ xticks: Arraylike
305
+ - Positions at which to place x-axis ticks.
306
+ xticklabels : list of str, optional
307
+ - Labels corresponding to `xticks`. Must be the same length as `xticks`.
245
308
  cbar: bool
246
309
  - Show colorbar
247
310
  - Default: True
@@ -274,6 +337,16 @@ class Fig:
274
337
  cbar = plt.colorbar(im, cax=curr_row[1])
275
338
  if label is not None:
276
339
  cbar.set_label(label, labelpad=5)
340
+
341
+ if yticks is not None:
342
+ curr_row[0].set_yticks(yticks)
343
+ if yticklabels is not None:
344
+ curr_row[0].set_yticklabels(yticklabels)
345
+
346
+ if xticks is not None:
347
+ curr_row[0].set_xticks(xticks)
348
+ if xticklabels is not None:
349
+ curr_row[0].set_xticklabels(xticklabels)
277
350
 
278
351
 
279
352
  def add_events(self, events, c=None, ls=None, lw=None, label=None, ax=None):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modusa
3
- Version: 0.3.64
3
+ Version: 0.3.66
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.64.dist-info/METADATA,sha256=OqkcnVTdmTrYVNCmAXmWNyrKkpGW9jyGuvHwSGTaBWE,1436
2
- modusa-0.3.64.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- modusa-0.3.64.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
- modusa-0.3.64.dist-info/licenses/LICENSE.md,sha256=JTaXAjx5awk76VArKCx5dUW8vmLEWsL_ZlR7-umaHbA,1078
1
+ modusa-0.3.66.dist-info/METADATA,sha256=AsSKHY45bDUxBNOXIi1zMAd6-otxsto690bzu8AA1h8,1436
2
+ modusa-0.3.66.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ modusa-0.3.66.dist-info/entry_points.txt,sha256=fmKpleVXj6CdaBVL14WoEy6xx7JQCs85jvzwTi3lePM,73
4
+ modusa-0.3.66.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=ICbDGtZJIuWC_97x9THacZACnLEbVbAvx2PFXxL-vIU,18410
53
+ modusa/tools/plotter.py,sha256=3Nw0L4txPELieN09gByvkSdgQHlXaRE0ES5rOmhJ7-Q,20937
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.64.dist-info/RECORD,,
62
+ modusa-0.3.66.dist-info/RECORD,,