Basicspython
Basicspython
"""
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
data_file = pd.read_csv(
"C:/Users/SohaPervez/Desktop/Mycodes/production_correction2.csv", sep=";",
header=1
)
testing_file = data_file.copy(deep=True)
start_with_ee = data_file[data_file["ID"].str.startswith("E")]
condd = testing_file["ID"].isin(start_with_ee["ID"])
testing_file.drop(testing_file[condd].index, inplace=True)
testing_file["ID"] = testing_file["ID"].str.replace("V", "")
testing_file.drop(
testing_file.columns[[2, 3]],
axis=1,
inplace=True,
)
# print(testing_file.corr())
median_file = data_file.copy(deep=True)
start_date = pd.to_datetime("2021-01-01")
end_date = pd.to_datetime("2023-04-14")
median_file["Start"] = pd.to_datetime(median_file["Start"])
all_medians = []
date_months = []
if filtered_data.size > 0:
filtered_median = (
(filtered_data["True output"] - filtered_data["Output"])
/ filtered_data["True output"]
).median()
all_medians.append(filtered_median)
date_months.append(start_date)
start_date = incremented_date
def plot_line_sim_true_output(input_file):
"""
Plots a line graph of true and simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=input_file["ID"],
y=input_file["Output"],
mode="lines",
name="Simulated output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.add_trace(
go.Scatter(
x=input_file["ID"],
y=input_file["True output"],
mode="lines",
name="True output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title="Line plots for simulated output and true output",
xaxis_title="Batch ID",
yaxis_title="simulated and true output",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/line_graph_true_and_simulated_output.
html"
)
def plot_style_line_sim_true_output(input_file):
"""
Plots a style line graph of true and simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=input_file["ID"],
y=input_file["Output"],
name="Simulated output",
line=dict(color="firebrick", width=4, dash="dash"),
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.add_trace(
go.Scatter(
x=input_file["ID"],
y=input_file["True output"],
name="True output",
line=dict(color="royalblue", width=4, dash="dot"),
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title="Style Line Plots for simulated and true output",
xaxis_title="Batch ID",
yaxis_title="simulated and true output",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/"
"style_line_graph_true_and_simulated_output.html"
)
def plot_line_batch_start_sim_true_output(input_file):
"""
Plots a line graph of batch start time vs true and simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=input_file["Start"],
y=input_file["Output"],
mode="lines",
name="Batch start time and the simulated output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.add_trace(
go.Scatter(
x=input_file["Start"],
y=input_file["True output"],
mode="lines",
name="Batch start time and the true output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title="Line plots of batch start time vs simluated and true output",
xaxis_title="Batch start",
yaxis_title="simulated and true output",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/"
"line_graph_batch_start_vs_true_and_simulated_output.html"
)
def plot_prop_errors(input_file):
"""
Plots a line graph of the Proportional errors.
Parameters:
input_file: pd.Dataframe
"""
new_data_file = input_file.copy(deep=True)
start_with_e = input_file[input_file["ID"].str.startswith("E")]
cond = new_data_file["ID"].isin(start_with_e["ID"])
new_data_file.drop(new_data_file[cond].index, inplace=True)
fig = go.Figure(
go.Scatter(
x=input_file.loc[input_file["ID"].str.startswith("E")]["Start"],
y=(
input_file.loc[input_file["ID"].str.startswith("E")]["True output"]
- input_file.loc[input_file["ID"].str.startswith("E")]["Output"]
)
/ input_file.loc[input_file["ID"].str.startswith("E")]["True output"],
mode="markers",
name="Sawline E",
customdata=np.stack(
(
input_file.loc[input_file["ID"].str.startswith("E")]["ID"],
input_file.loc[input_file["ID"].str.startswith("E")]
["Pattern"],
input_file.loc[input_file["ID"].str.startswith("E")]["Start"],
input_file.loc[input_file["ID"].str.startswith("E")]["End"],
input_file.loc[input_file["ID"].str.startswith("E")]["Output"],
input_file.loc[input_file["ID"].str.startswith("E")]["True
output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{customdata[2]|%Y-%m-%d} %
{customdata[2]|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
+ "<extra></extra>",
showlegend=True,
)
)
fig.add_trace(
go.Scatter(
x=new_data_file["Start"],
y=(new_data_file["True output"] - new_data_file["Output"])
/ new_data_file["True output"],
mode="markers",
name="Sawline V",
customdata=np.stack(
(
new_data_file["ID"],
new_data_file["Pattern"],
new_data_file["Start"],
new_data_file["End"],
new_data_file["Output"],
new_data_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{customdata[2]|%Y-%m-%d} %
{customdata[2]|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
+ "<extra></extra>",
showlegend=True,
)
)
fig.add_trace(
go.Scatter(
x=df1["Date"],
y=df1["Median"],
mode="lines",
name="Median",
customdata=np.stack(
(
df1["Date"],
df1["Median"],
),
axis=-1,
),
hovertemplate="<b>Date</b>: %{customdata[0]}<br>"
+ "<b>Median</b>: %{customdata[1]}<br>"
+ "<extra></extra>",
showlegend=True,
)
)
fig.update_layout(
title="Comparision of proportional errors for E and V sawlines",
xaxis_title="Batch start time",
yaxis_title="(True output - simulated output)/True output",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/line_graph_proportional_errors.html"
)
def hovertemplate_errors(input_file):
"""
Creates a hovertemplate for the diff between true and simulated output
(errors).
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=input_file["Start"],
y=input_file["True output"] - input_file["Output"],
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Start"],
input_file["End"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date</b>: %{x|%Y-%m-%d} <b>Batch start time</b>: %{x|
%H:%M:%S}<br>"
+ "<b>Batch end date</b>: %{customdata[3]|%Y-%m-%d}<br>"
"<b>Batch end time</b>: %{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title="Hovertemplate for errors",
xaxis_title="Batch start time",
yaxis_title="Errors",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/hovertemplate_errors.html"
)
def hovertemplate_e_v_sawlines(input_file):
"""
Creates a hovertemplate separate for E and V sawlines.
Parameters:
input_file: pd.Dataframe
"""
new_data_file = input_file.copy(deep=True)
start_with_e = input_file[input_file["ID"].str.startswith("E")]
cond = new_data_file["ID"].isin(start_with_e["ID"])
new_data_file.drop(new_data_file[cond].index, inplace=True)
fig = go.Figure(
go.Scatter(
x=input_file.loc[input_file["ID"].str.startswith("E")]["Start"],
y=input_file.loc[input_file["ID"].str.startswith("E")]["True output"]
- input_file.loc[input_file["ID"].str.startswith("E")]["Output"],
name="Sawline E",
customdata=np.stack(
(
input_file.loc[input_file["ID"].str.startswith("E")]["ID"],
input_file.loc[input_file["ID"].str.startswith("E")]
["Pattern"],
input_file.loc[input_file["ID"].str.startswith("E")]["Start"],
input_file.loc[input_file["ID"].str.startswith("E")]["End"],
input_file.loc[input_file["ID"].str.startswith("E")]["Output"],
input_file.loc[input_file["ID"].str.startswith("E")]["True
output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{x|%Y-%m-%d} %{x|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
+ "<extra></extra>",
showlegend=True,
)
)
fig.add_trace(
go.Scatter(
x=new_data_file["Start"],
y=new_data_file["True output"] - new_data_file["Output"],
name="Sawline V",
customdata=np.stack(
(
new_data_file["ID"],
new_data_file["Pattern"],
new_data_file["Start"],
new_data_file["End"],
new_data_file["Output"],
new_data_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{x|%Y-%m-%d} %{x|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
+ "<extra></extra>",
showlegend=True,
)
)
fig.update_layout(
title="Comparision of absolute error for E and V sawlines",
xaxis_title="Batch start time",
yaxis_title="True output - simulated output",
)
fig.update_traces(mode="markers")
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/hovertemplate_for_E_V_sawlines.html"
)
def dist_proportional_errors(input_file):
"""
Creates a histogram (distribution) for the proportional errors.
Parameters:
input_file: pd.Dataframe
"""
new_data_file = input_file.copy(deep=True)
start_with_e = input_file[input_file["ID"].str.startswith("E")]
cond = new_data_file["ID"].isin(start_with_e["ID"])
new_data_file.drop(new_data_file[cond].index, inplace=True)
fig = go.Figure()
fig.add_trace(
go.Histogram(
x=(
data_file.loc[data_file["ID"].str.startswith("E")]["True output"]
- data_file.loc[data_file["ID"].str.startswith("E")]["Output"]
)
/ data_file.loc[data_file["ID"].str.startswith("E")]["True output"],
nbinsx=50,
name="Sawline E",
hovertemplate="<b>Proportional error</b>: %{x}<br>"
"<b>Count</b>: %{y}<br>",
showlegend=True,
)
)
fig.add_trace(
go.Histogram(
x=(input_file["True output"] - input_file["Output"])
/ input_file["True output"],
name="Sawline V",
xbins=dict(start=-0.4, end=1.0, size=0.01),
hovertemplate="<b>Proportional error</b>: %{x}<br>"
"<b>Count</b>: %{y}<br>",
showlegend=True,
)
)
fig.update_layout(
barmode="overlay",
title_text="Distribution of proportional errors", # title of plot
xaxis_title_text="(True output - simulated output)/True output", # xaxis
label
)
fig.update_traces(opacity=0.65)
fig.update_yaxes(showticklabels=False)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/distribution_of_proportional_errors.h
tml"
)
def dist_simulated_output(input_file):
"""
Creates a histogram (distribution) for the simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure(
data=go.Histogram(
x=input_file["Output"],
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title_text="Distribution of simulated output", # title of plot
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/distribution_of_simulated_output.html
"
)
def dist_true_output(input_file):
"""
Creates a histogram (distribution) for the true output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure(
data=go.Histogram(
x=input_file["True output"],
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.update_layout(
title_text="Distribution of true output", # title of plot
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/distribution_of_true_output.html"
)
def stacked_histogram(input_file):
"""
Creates a stacked histogram for true and simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Histogram(
x=input_file["True output"],
name="True output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.add_trace(
go.Histogram(
x=input_file["Output"],
name="Simulated output",
customdata=np.stack(
(
input_file["ID"],
input_file["Pattern"],
input_file["Output"],
input_file["True output"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Simulated output</b>: %{customdata[2]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[3]:,.0f}<br>"
+ "<extra></extra>",
showlegend=False,
)
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/stacked_histogram_true_simulated.html
"
)
def overlaid_histogram(input_file):
"""
Creates a overlaid histogram for true and simulated output.
Parameters:
input_file: pd.Dataframe
"""
fig = go.Figure()
fig.add_trace(
go.Histogram(
x=input_file["True output"],
name="True output",
hovertemplate="<b>True output</b>: %{x}<br>" "<b>Count</b>: %{y}<br>",
showlegend=True,
)
)
fig.add_trace(
go.Histogram(
x=input_file["Output"],
name="Simulated output",
hovertemplate="<b>Simulated output</b>: %{x}<br>" "<b>Count</b>: %
{y}<br>",
showlegend=True,
)
)
fig.update_layout(
barmode="overlay",
title_text="Comparision of true output and simulated output",
xaxis_title_text="Output",
)
fig.update_traces(opacity=0.65)
fig.update_yaxes(showticklabels=False)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/overlaid_histogram_true_simulated.htm
l"
)
def absolute_error(input_file):
"""
Creates a histogram (distribution) for the absolute errors.
Parameters:
input_file: pd.Dataframe
"""
new_data_file = input_file.copy(deep=True)
start_with_e = input_file[input_file["ID"].str.startswith("E")]
cond = new_data_file["ID"].isin(start_with_e["ID"])
new_data_file.drop(new_data_file[cond].index, inplace=True)
fig = go.Figure()
fig.add_trace(
go.Histogram(
x=data_file.loc[data_file["ID"].str.startswith("E")]["True output"]
- data_file.loc[data_file["ID"].str.startswith("E")]["Output"],
nbinsx=200,
name="Sawline E",
hovertemplate="<b>Absolute error</b>: %{x}<br>" "<b>Count</b>: %
{y}<br>",
showlegend=True,
)
)
fig.add_trace(
go.Histogram(
x=new_data_file["True output"] - new_data_file["Output"],
name="Sawline V",
nbinsx=100,
hovertemplate="<b>Absolute error</b>: %{x}<br>" "<b>Count</b>: %
{y}<br>",
showlegend=True,
)
)
fig.update_traces(opacity=0.65)
fig.update_yaxes(showticklabels=False)
fig.update_layout(
barmode="overlay",
title_text="Distribution of absolute errors", # title of plot
xaxis_title_text="True - simulated output", # xaxis label
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/distribution_of_absolute_errors.html"
)
def box_plot_prop_vs_sawpattern(input_file):
"""
Creates a boxplot for the absolute errors.
Parameters:
input_file: pd.Dataframe
"""
new_data_file = input_file.copy(deep=True)
start_with_e = input_file[input_file["ID"].str.startswith("E")]
cond = new_data_file["ID"].isin(start_with_e["ID"])
new_data_file.drop(new_data_file[cond].index, inplace=True)
fig = go.Figure()
fig = make_subplots(
rows=2,
cols=1,
subplot_titles=(
"Boxplot for sawing patterns E vs proportional errors",
"Boxplot for sawing patterns V vs proportional errors",
),
)
fig.append_trace(
go.Box(
x=x_1,
y=y_1,
boxpoints="all",
name="Sawline E",
customdata=customdata_1,
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{customdata[2]|%Y-%m-%d} %
{customdata[2]|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
"<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=1,
col=1,
)
fig.append_trace(
go.Box(
x=x_2,
y=y_2,
boxpoints="all",
name="Sawline V",
customdata=customdata_2,
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Batch start date & time</b>: %{customdata[2]|%Y-%m-%d} %
{customdata[2]|%H:%M:%S}<br>"
+ "<b>Batch end date & time</b>: %{customdata[3]|%Y-%m-%d} %
{customdata[3]|%H:%M:%S}<br>"
+ "<b>Simulated output</b>: %{customdata[4]:,.0f}<br>"
+ "<b>True output</b>: %{customdata[5]:,.0f}<br>"
"<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=2,
col=1,
)
fig.update_layout(
title_text="Boxplot for sawing patterns vs proportional errors ((true
output - simulated output)/true output)",
title_x=0.5,
yaxis_title_text="(True output - simulated output)/True output",
)
fig.write_html(
"C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/boxplot_of_pattern.html"
)
Parameters
----------
input_file : pandas.Dataframe
"""
corr_data = input_file.copy(deep=True)
corr_data["Start"] = pd.to_datetime(corr_data["Start"])
start_with_e = filtered_1[filtered_1["ID"].str.startswith("E")]
cond = filtered_1["ID"].isin(start_with_e["ID"])
filtered_1.drop(filtered_1[cond].index, inplace=True)
fig = go.Figure()
fig = make_subplots(
rows=3,
cols=3,
subplot_titles=(
"Proportional error vs Size",
"Proportional error vs Input",
"Proportional error vs Output",
"Proportional error vs RVE",
"Proportional error vs True input",
"Proportional error vs True output",
{},
"Proportional error vs True RVE",
{},
),
)
fig.add_trace(
go.Scatter(
x=filtered_1["Size"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="Size",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=filtered_1["Input"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="Input",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=1,
col=2,
)
fig.add_trace(
go.Scatter(
x=filtered_1["Output"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="Output",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=1,
col=3,
)
fig.add_trace(
go.Scatter(
x=filtered_1["RVE"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="RVE",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=2,
col=1,
)
fig.add_trace(
go.Scatter(
x=filtered_1["True input"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="True input",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=2,
col=2,
)
fig.add_trace(
go.Scatter(
x=filtered_1["True output"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="True output",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=2,
col=3,
)
fig.add_trace(
go.Scatter(
x=filtered_1["True RVE"],
y=(filtered_1["True output"] - filtered_1["Output"])
/ filtered_1["True output"],
name="True RVE",
mode="markers",
opacity=0.5,
customdata=np.stack(
(
filtered_1["ID"],
filtered_1["Pattern"],
),
axis=-1,
),
hovertemplate="<b>Batch ID</b>: %{customdata[0]}<br>"
+ "<b>Pattern</b>: %{customdata[1]}<br>"
+ "<b>Proportinal error</b>: %{y}<br>",
showlegend=True,
),
row=3,
col=2,
)
fig.update_layout(
title_text="Plots of multiple variables vs proportional error ((true output
- simulated output)/true output)",
title_x=0.5,
)
fig.write_html("C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/new_correlogram.html")
Parameters
----------
input_file : pandas.DataFrame
"""
corr_data = input_file.copy(deep=True)
corr_data["Start"] = pd.to_datetime(corr_data["Start"])
start_with_e = filtered_1[filtered_1["ID"].str.startswith("E")]
cond = filtered_1["ID"].isin(start_with_e["ID"])
filtered_1.drop(filtered_1[cond].index, inplace=True)
x = corr_data["Input"]
y = corr_data["Output"]
z = (corr_data["True output"] - corr_data["Output"]) / corr_data["True output"]
fig = go.Figure(
data=[
go.Scatter3d(
x=x,
y=y,
z=z,
mode="markers",
marker=dict(size=7, color=z, colorscale="Viridis", opacity=0.5),
)
]
)
fig.update_layout(
title_text="3D plot for input, output and proportional error",
title_x=0.5,
scene=dict(
xaxis_title="Input",
yaxis_title="Output",
zaxis_title="Proportional error",
zaxis=dict(range=[-0.2, 0.2]),
),
)
fig.write_html("C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/3D_plot.html")
Parameters
----------
input_file : pandas.DataFrame
"""
corr_data = input_file.copy(deep=True)
corr_data["Start"] = pd.to_datetime(corr_data["Start"])
start_with_e = filtered_1[filtered_1["ID"].str.startswith("E")]
cond = filtered_1["ID"].isin(start_with_e["ID"])
filtered_1.drop(filtered_1[cond].index, inplace=True)
x = corr_data["Input"]
y = corr_data["RVE"]
z = (corr_data["True output"] - corr_data["Output"]) / corr_data["True output"]
fig = go.Figure(
data=[
go.Scatter3d(
x=x,
y=y,
z=z,
mode="markers",
marker=dict(
size=7,
color=corr_data["Pattern"],
colorscale="Viridis",
opacity=0.5,
),
)
]
)
fig.update_layout(
title_text="3D plot for input, RVE and proportional error",
title_x=0.5,
scene=dict(
xaxis_title="Input",
yaxis_title="RVE",
zaxis_title="Proportional error",
zaxis=dict(range=[-0.2, 0.2]),
yaxis=dict(range=[1.5, 3]),
xaxis=dict(range=[0, 2000]),
),
)
fig.write_html("C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/3D_plot_irp.html")
Parameters
----------
input_file : pandas.DataFrame
"""
corr_data = input_file.copy(deep=True)
corr_data["Start"] = pd.to_datetime(corr_data["Start"])
start_with_e = filtered_1[filtered_1["ID"].str.startswith("E")]
cond = filtered_1["ID"].isin(start_with_e["ID"])
filtered_1.drop(filtered_1[cond].index, inplace=True)
x = corr_data["Output"]
y = corr_data["RVE"]
z = (corr_data["True output"] - corr_data["Output"]) / corr_data["True output"]
fig = go.Figure(
data=[
go.Scatter3d(
x=x,
y=y,
z=z,
mode="markers",
marker=dict(
size=7,
color=corr_data["Pattern"],
colorscale="Viridis",
opacity=0.5,
),
)
]
)
fig.update_layout(
title_text="3D plot for output, RVE and proportional error",
title_x=0.5,
scene=dict(
xaxis_title="Output",
yaxis_title="RVE",
zaxis_title="Proportional error",
zaxis=dict(range=[-0.2, 0.2]),
yaxis=dict(range=[1.5, 3]),
xaxis=dict(range=[0, 1000]),
),
)
fig.write_html("C:/Users/SohaPervez/Desktop/Mycodes/pygraphs/3D_plot_orp.html")
plot_line_sim_true_output(data_file)
plot_style_line_sim_true_output(data_file)
plot_line_batch_start_sim_true_output(data_file)
plot_prop_errors(data_file)
hovertemplate_e_v_sawlines(data_file)
dist_proportional_errors(data_file)
dist_simulated_output(data_file)
dist_true_output(data_file)
stacked_histogram(data_file)
overlaid_histogram(data_file)
absolute_error(data_file)
box_plot_prop_vs_sawpattern(data_file)
correlogram(data_file)
three_d_plot(data_file)
three_d_plot_irp(data_file)
three_d_plot_orp(data_file)