-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarFile.py
More file actions
140 lines (84 loc) · 3.81 KB
/
Copy pathBarFile.py
File metadata and controls
140 lines (84 loc) · 3.81 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import tkinter as tk
from tkinter import filedialog
from tkinter import PhotoImage
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from tkinter import ttk
import customtkinter as ctk
from PIL import ImageTk, Image
class Bar:
def __init__(self, win, df):
self.win = win
self.df = df
def __call__(self):
ctk.set_appearance_mode("dark")
def makeBarGraph():
new_window = ctk.CTkToplevel(self.win)
new_window.title('Bar Graph')
new_window.geometry('400x400')
x_axis = selection1.index(bar_clicked1.get())
y_axis = selection1.index(bar_clicked2.get())
labels = self.df.iloc[:int(bar_clicked.get()), x_axis]
data = self.df.iloc[:int(bar_clicked.get()), y_axis]
label_values = []
numerical_vals = []
for val in labels:
label_values.append(val)
for element in data:
numerical_vals.append(element)
plt.bar(label_values, numerical_vals)
fig = plt.figure(1)
canvas = FigureCanvasTkAgg(fig, master=new_window)
plot_widget = canvas.get_tk_widget()
plot_widget.pack()
options = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"]
# Creation of main bar window controls and configurations
icon_image = PhotoImage(file="DatafyLogo.png")
bar_clicked = tk.IntVar()
bar_clicked.set(2)
selection1 = list(self.df.columns.values)
selection2 = list(self.df.columns.values)
bar_page = ctk.CTkToplevel(self.win)
bar_page.title('Bar Graph')
bar_page.geometry('400x400')
bar_page.iconphoto(False, icon_image)
barTitle = ctk.CTkLabel(master=bar_page,
text="Bar Graph", text_color="#399adb",
font=('Comic Sans Bold', 25))
barTitle.pack()
questionLabel = ctk.CTkLabel(
master=bar_page,
text="How many column labels of information would you like?", text_color="#399adb",
font=('Comic Sans', 15),
width=50)
questionLabel.pack(padx=10, pady=2)
dropdown = ctk.CTkOptionMenu(master=bar_page, variable=bar_clicked, values=options, fg_color="#399adb", dropdown_fg_color="#399adb")
dropdown.pack(padx=10, pady=3)
# Creation of x-axis dropdown and labels for bar graph
questionLabel = ctk.CTkLabel(
master=bar_page,
text="What selection of data would like to choose for the x-axis?", text_color="#399adb", font=('Comic Sans', 15))
questionLabel.pack(padx=10, pady=6)
bar_clicked1 = tk.StringVar()
bar_clicked1.set(selection1[0])
xAxisDropdown = ctk.CTkOptionMenu(master=bar_page, variable=bar_clicked1, values=selection1, fg_color="#399adb", dropdown_fg_color="#399adb")
xAxisDropdown.pack(padx=10, pady=7)
#------------------------------------------------
# Creation of y-axis dropdown menu and labels for bar graph
questionLabel2 = ctk.CTkLabel(
master=bar_page,
text="What selection of data would like to choose for the y-axis?", font=("Comic Sans", 15), text_color="#399adb")
questionLabel2.pack(padx=10, pady=9)
bar_clicked2 = tk.StringVar()
bar_clicked2.set(selection1[1])
yAxisDropdown = ctk.CTkOptionMenu(master=bar_page, variable=bar_clicked2, values=selection2, fg_color="#399adb", dropdown_fg_color="#399adb")
yAxisDropdown.pack(padx=10, pady=10)
barLabel = ctk.CTkLabel(master=bar_page,
text="Click the button below to make a bar graph!", font=("Comic Sans", 15), text_color="#399adb")
barLabel.pack()
bg_button = ctk.CTkButton(master=bar_page,
text="Plot Bar Graph",
height=25, font=("Arial", 15), corner_radius=10,
command=makeBarGraph)
bg_button.pack()