nahue-passano commited on
Commit
4b13d53
·
verified ·
1 Parent(s): 7c09abf

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +103 -7
visualization.py CHANGED
@@ -56,14 +56,15 @@ def plotly_full_figure(
56
  single_speaker=False,
57
  ):
58
  fig = make_subplots(
59
- rows=3,
60
  cols=1,
61
- shared_xaxes=True,
62
- vertical_spacing=0.05,
63
  specs=[
64
  [{"secondary_y": True}],
65
  [{"secondary_y": True}],
66
  [{"secondary_y": True}],
 
67
  ], # Enable secondary y-axis for both rows
68
  )
69
 
@@ -166,6 +167,38 @@ def plotly_full_figure(
166
  col=1,
167
  secondary_y=True,
168
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  ###### Speaker 2
171
  if not single_speaker:
@@ -267,6 +300,40 @@ def plotly_full_figure(
267
  col=1,
268
  secondary_y=True,
269
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
 
271
  ### Update layout
272
  fig.update_layout(
@@ -282,6 +349,11 @@ def plotly_full_figure(
282
  range=[np.log10(10), np.log10(4000)],
283
  ),
284
  xaxis3=dict(
 
 
 
 
 
285
  title="Frequency [Hz]",
286
  titlefont=dict(size=14),
287
  tickfont=dict(size=12),
@@ -313,9 +385,24 @@ def plotly_full_figure(
313
  ticktext=["-180º", "-90º", "0º", "90º", "180º"],
314
  range=[-180, 180],
315
  ),
316
- legend=dict(font=dict(size=10), x=0.85, y=0.99),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  width=1200,
318
- height=800,
319
  margin=dict(l=20, r=20, t=30, b=20),
320
  annotations=[
321
  dict(
@@ -330,7 +417,7 @@ def plotly_full_figure(
330
  dict(
331
  text="<b>Electrical Impedance</b>",
332
  x=0.47,
333
- y=0.68,
334
  xref="paper",
335
  yref="paper",
336
  showarrow=False,
@@ -339,7 +426,16 @@ def plotly_full_figure(
339
  dict(
340
  text="<b>Mechanical Velocity</b>",
341
  x=0.47,
342
- y=0.30,
 
 
 
 
 
 
 
 
 
343
  xref="paper",
344
  yref="paper",
345
  showarrow=False,
 
56
  single_speaker=False,
57
  ):
58
  fig = make_subplots(
59
+ rows=4,
60
  cols=1,
61
+ shared_xaxes=False,
62
+ vertical_spacing=0.1,
63
  specs=[
64
  [{"secondary_y": True}],
65
  [{"secondary_y": True}],
66
  [{"secondary_y": True}],
67
+ [{"secondary_y": True}],
68
  ], # Enable secondary y-axis for both rows
69
  )
70
 
 
167
  col=1,
168
  secondary_y=True,
169
  )
170
+ ### Mechanical displacement
171
+ fig.add_trace(
172
+ go.Scatter(
173
+ x=freq_array,
174
+ y=np.abs(loudspeaker_responses_1["mechanical_displacement"]),
175
+ mode="lines",
176
+ name="Speaker 1",
177
+ line=dict(color="blue"),
178
+ hovertemplate="%{x:.2f} Hz<br>%{y:.2f} " + "mm",
179
+ legendgroup="Speaker 1 (Magnitude)",
180
+ showlegend=False,
181
+ ),
182
+ row=4,
183
+ col=1,
184
+ secondary_y=False,
185
+ )
186
+
187
+ fig.add_trace(
188
+ go.Scatter(
189
+ x=freq_array,
190
+ y=np.angle(loudspeaker_responses_1["mechanical_displacement"], deg=True),
191
+ mode="lines",
192
+ name="Speaker 1",
193
+ line=dict(color="red"),
194
+ hovertemplate="%{x:.2f} Hz<br>%{y:.2f} º",
195
+ legendgroup="Speaker 1 (Phase)",
196
+ showlegend=False,
197
+ ),
198
+ row=4,
199
+ col=1,
200
+ secondary_y=True,
201
+ )
202
 
203
  ###### Speaker 2
204
  if not single_speaker:
 
300
  col=1,
301
  secondary_y=True,
302
  )
303
+ ### Mechanical displacement
304
+ fig.add_trace(
305
+ go.Scatter(
306
+ x=freq_array,
307
+ y=np.abs(loudspeaker_responses_2["mechanical_displacement"]),
308
+ mode="lines",
309
+ name="Speaker 2",
310
+ line=dict(color="blue", dash="dot"),
311
+ hovertemplate="%{x:.1f} Hz<br>%{y:.1f} " + "mm",
312
+ legendgroup="Speaker 2 (Magnitude)",
313
+ showlegend=False,
314
+ ),
315
+ row=4,
316
+ col=1,
317
+ secondary_y=False,
318
+ )
319
+
320
+ fig.add_trace(
321
+ go.Scatter(
322
+ x=freq_array,
323
+ y=np.angle(
324
+ loudspeaker_responses_2["mechanical_displacement"], deg=True
325
+ ),
326
+ mode="lines",
327
+ name="Speaker 2",
328
+ line=dict(color="red", dash="dot"),
329
+ hovertemplate="%{x:.1f} Hz<br>%{y:.1f} º",
330
+ legendgroup="Speaker 2 (Phase)",
331
+ showlegend=False,
332
+ ),
333
+ row=4,
334
+ col=1,
335
+ secondary_y=True,
336
+ )
337
 
338
  ### Update layout
339
  fig.update_layout(
 
349
  range=[np.log10(10), np.log10(4000)],
350
  ),
351
  xaxis3=dict(
352
+ type="log",
353
+ tickvals=[16, 31, 63, 125, 250, 500, 1000, 2000, 4000],
354
+ range=[np.log10(10), np.log10(4000)],
355
+ ),
356
+ xaxis4=dict(
357
  title="Frequency [Hz]",
358
  titlefont=dict(size=14),
359
  tickfont=dict(size=12),
 
385
  ticktext=["-180º", "-90º", "0º", "90º", "180º"],
386
  range=[-180, 180],
387
  ),
388
+ yaxis7=dict(title="Displacement [mm]", color="blue"),
389
+ yaxis8=dict(
390
+ title="Phase [º]",
391
+ color="red",
392
+ tickvals=[-180, -90, 0, 90, 180],
393
+ ticktext=["-180º", "-90º", "0º", "90º", "180º"],
394
+ range=[-180, 180],
395
+ ),
396
+ legend=dict(
397
+ font=dict(size=10),
398
+ x=0.245,
399
+ y=1.06,
400
+ orientation="h",
401
+ itemwidth=30,
402
+ ),
403
+ showlegend=not single_speaker,
404
  width=1200,
405
+ height=1000,
406
  margin=dict(l=20, r=20, t=30, b=20),
407
  annotations=[
408
  dict(
 
417
  dict(
418
  text="<b>Electrical Impedance</b>",
419
  x=0.47,
420
+ y=0.755,
421
  xref="paper",
422
  yref="paper",
423
  showarrow=False,
 
426
  dict(
427
  text="<b>Mechanical Velocity</b>",
428
  x=0.47,
429
+ y=0.47,
430
+ xref="paper",
431
+ yref="paper",
432
+ showarrow=False,
433
+ font=dict(size=18),
434
+ ),
435
+ dict(
436
+ text="<b>Mechanical Displacement</b>",
437
+ x=0.47,
438
+ y=0.175,
439
  xref="paper",
440
  yref="paper",
441
  showarrow=False,