def plot_temperature_data(
dftemp,
orig_data_column="process_temperature_K",
gap_column="process_temperature_K_gaps",
int_column=None,
):
if int_column is not None:
dff = dftemp[["UDI", gap_column, int_column]].copy()
dff.loc[~dftemp[gap_column].isna(), int_column] = None
# Plot the difference between original and imputed as a separate subplot
diff = dftemp[orig_data_column] - dff[int_column]
# Create subplots: first for temperature, second for difference
fig = make_subplots(
rows=2,
cols=1,
shared_xaxes=True,
vertical_spacing=0.1,
subplot_titles=(
"Process Temperature With and Without Gaps",
"Original - Imputed Difference",
),
)
# Top plot: original, gaps, imputed
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp[orig_data_column],
mode="lines",
name="Original",
line=dict(color="lightgrey"),
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp[gap_column],
mode="lines",
name="With Gaps",
),
row=1,
col=1,
)
dff = dftemp[["UDI", gap_column, int_column]].copy()
dff.loc[~dftemp[gap_column].isna(), int_column] = None
fig.add_trace(
go.Scatter(
x=dff["UDI"],
y=dff[int_column],
mode="lines",
name="Imputed",
line=dict(color="blue"),
),
row=1,
col=1,
)
# Bottom plot: difference
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=diff,
mode="lines",
name="Original - Imputed",
line=dict(color="green"),
),
row=2,
col=1,
)
fig.update_layout(
height=700,
title_text="Process Temperature With and Without Gaps and Imputation Difference",
xaxis_title="UDI",
yaxis_title="Process Temperature [K]",
)
fig.update_yaxes(title_text="Process Temperature [K]", row=1, col=1)
fig.update_yaxes(title_text="Difference", row=2, col=1)
else:
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp[orig_data_column],
mode="lines",
name="Original",
line=dict(color="lightgrey"),
)
)
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp[gap_column],
mode="lines",
name="With Gaps",
)
)
fig.update_layout(
title="Process Temperature With and Without Gaps",
xaxis_title="UDI",
yaxis_title="Process Temperature [K]",
)
fig.show()
def plot_smoothed_temperature_data(dftemp, smoothed_column):
# Calculate difference
diff = dftemp["process_temperature_K"] - dftemp[smoothed_column]
# Create subplots: first for temperature, second for difference
fig = make_subplots(
rows=2,
cols=1,
shared_xaxes=True,
vertical_spacing=0.1,
subplot_titles=(
"Process Temperature: Original vs Smoothed",
"Original - Smoothed Difference",
),
)
# Top plot: original and smoothed
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp["process_temperature_K"],
mode="lines",
name="Original",
line=dict(color="lightgrey"),
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=dftemp[smoothed_column],
mode="lines",
name="Smoothed",
line=dict(color="blue"),
),
row=1,
col=1,
)
# Bottom plot: difference
fig.add_trace(
go.Scatter(
x=dftemp["UDI"],
y=diff,
mode="lines",
name="Original - Smoothed",
line=dict(color="green"),
),
row=2,
col=1,
)
fig.update_layout(
height=700,
title_text="Process Temperature: Original, Smoothed, and Difference",
xaxis_title="UDI",
)
fig.update_yaxes(title_text="Process Temperature [K]", row=1, col=1)
fig.update_yaxes(title_text="Difference", row=2, col=1)
fig.show()