-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigure_3_GUI.py
More file actions
86 lines (61 loc) · 2.69 KB
/
Copy pathFigure_3_GUI.py
File metadata and controls
86 lines (61 loc) · 2.69 KB
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
import tkinter as tk
from tkinter import ttk, colorchooser
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
data = pd.read_csv('Maintenance_Data.csv')
fault_columns = ['TWF', 'HDF', 'PWF', 'OSF', 'RNF']
numerical_columns = ['Air temperature [K]', 'Process temperature [K]', 'Rotational speed [rpm]', 'Torque [Nm]', 'Tool wear [min]']
box_plot_color = "#ffffff"
def update_sliders(*args):
global y_min_scale, y_max_scale
selected_column = y_axis_var.get()
y_min = data[selected_column].min()
y_max = data[selected_column].max()
y_min_scale.config(from_=y_min, to=y_max)
y_min_scale.set(y_min)
y_max_scale.config(from_=y_min, to=y_max)
y_max_scale.set(y_max)
def update_box_plot():
global box_plot_color
column = y_axis_var.get()
y_min = y_min_scale.get()
y_max = y_max_scale.get()
fig.clear()
ax = fig.add_subplot(111)
for fault in fault_columns:
subset = data[(data[fault] == 1) & (data[column] >= y_min) & (data[column] <= y_max)]
ax.boxplot(subset[column], positions=[fault_columns.index(fault)], widths=0.6, patch_artist=True, boxprops=dict(facecolor=box_plot_color))
ax.set_xticks(range(len(fault_columns)))
ax.set_xticklabels(fault_columns)
ax.set_ylim(y_min, y_max)
ax.set_ylabel(column)
ax.set_title('Box plot of Fault Types vs. ' + column)
canvas.draw()
def choose_color():
global box_plot_color
color_code = colorchooser.askcolor(title="Choose Box Plot Color")
if color_code[1] is not None:
box_plot_color = color_code[1]
update_box_plot()
root = tk.Tk()
root.title("Interactive Box Plot")
y_axis_var = tk.StringVar(root)
y_axis_var.trace("w", update_sliders)
y_axis_dropdown = ttk.Combobox(root, textvariable=y_axis_var, values=numerical_columns)
y_axis_dropdown.grid(row=0, column=0, padx=10, pady=10)
y_axis_dropdown.current(0)
y_min_scale = tk.Scale(root, orient=tk.HORIZONTAL, label="Y-min")
y_min_scale.grid(row=1, column=0, padx=10, pady=10)
y_max_scale = tk.Scale(root, orient=tk.HORIZONTAL, label="Y-max")
y_max_scale.grid(row=2, column=0, padx=10, pady=10)
update_sliders()
update_button = tk.Button(root, text="Update Plot", command=update_box_plot)
update_button.grid(row=3, column=0, padx=10, pady=10)
color_button = tk.Button(root, text="Choose Box Plot Color", command=choose_color)
color_button.grid(row=4, column=0, padx=10, pady=10)
fig = plt.Figure(figsize=(6, 4), dpi=100)
canvas = FigureCanvasTkAgg(fig, master=root)
widget = canvas.get_tk_widget()
widget.grid(row=0, column=1, rowspan=5, padx=10, pady=10)
root.mainloop()