-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_functions.py
88 lines (79 loc) · 2.56 KB
/
figure_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import plotly.graph_objects as go
from constants import PLOTLY_THEME
def make_spectrum_with_picked_peaks(
x,
y,
peaks,
fwhm,
hm,
leftips,
rightips,
plotly_theme=PLOTLY_THEME,
):
"""Make a plotly figure from peak parameters
Args:
x (numpy.ndarray): 1D vector of the x values of a waveform
y (numpy.ndarray): 1D vector of the x values of a waveform
peaks (numpy.ndarray): 1D vector of peaks from waveform
fwhm (numpy.ndarray): 1D vector of full-width-at-half-maxima values
hm (numpy.ndarray): 1D vector of the heights of the fwhm array
leftips (numpy.ndarray): Interpolated positions of left intersection points
of a horizontal line at the respective evaluation height
rightips (numpy.ndarray): same as leftips except on the right side
plotly_theme (str): theme for plotly. If none specified, default of "ggplot" is
used
Returns:
go.Figure
"""
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, mode="lines", name="original"))
fig.add_trace(go.Scatter(x=x[peaks], y=y[peaks], mode="markers", name="peaks"))
for i in range(len(hm)):
fig.add_trace(
go.Scatter(
x=x[leftips[i] : rightips[i]],
y=[hm[i]] * fwhm[i],
mode="lines",
name="peak" + str(i + 1),
)
)
fig.update_layout(template=plotly_theme)
return fig
def make_fig_for_diff_tables(df, tolerance):
"""Makes plotly figure for visualizing the differences with tolerances
Args:
df (pd.DataFrame): dataframe to be visualized
tolerance (float): tolerance associated with that dataframe
Returns:
plotly figure
"""
fig = go.Figure()
for i in range(df.shape[0]):
fig.add_trace(
go.Scatter(
x=df.columns,
y=df.iloc[i, :].values,
name="Sample " + str(i + 1),
mode="lines+markers",
)
)
fig.add_trace(
go.Scatter(
x=df.columns,
y=[tolerance] * len(df.columns),
name="upper limit",
mode="lines",
line=dict(color="firebrick", width=2, dash="dash"),
)
)
fig.add_trace(
go.Scatter(
x=df.columns,
y=[-tolerance] * len(df.columns),
name="lower limit",
mode="lines",
line=dict(color="firebrick", width=2, dash="dash"),
)
)
fig.update_layout(template=PLOTLY_THEME)
return fig