-
Notifications
You must be signed in to change notification settings - Fork 4
/
graphly4.0.1.py
295 lines (193 loc) · 9.19 KB
/
graphly4.0.1.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
"""
Created on Thu Jun 3 18:50:28 2021
Graphy 4.0.1
@author: Kylo Ren
"""
"""Updated Version of Graphly , now adding values will be easier.
Tried to put altogether in a single file.
Try the GUI and send feedbacks.
"""
# Libraries -------------------------------------------------------------------------------
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg , NavigationToolbar2Tk
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import numpy as np
import tkinter
# Functions ---------------------------------------------------------------------------------
def negpow(arr, k):
xx = arr.tolist()
ar = []
for i in xx:
ar.append( pow( i, k ) )
return np.array( ar )
def Exit():
if tkinter.messagebox.askquestion( 'Exit ', 'Do you really want to exit ?' ) == 'yes':
root.destroy()
def coef_apply_fn():
try :
x1 = int( coef_lower_entry.get() )
x2 = int( coef_upper_entry.get() )
coef_lower_entry.delete( 0, tkinter.END )
coef_upper_entry.delete( 0, tkinter.END )
assert x1<=x2
coef_scaler.config( from_ = x1, to = x2 )
except :
coef_lower_entry.delete( 0, tkinter.END )
coef_upper_entry.delete( 0, tkinter.END )
tkinter.messagebox.showwarning( "Add Coefficients", "Add valid numbers!" )
def power_apply_fn():
try :
x1 = int( power_lower_entry.get() )
x2 = int( power_upper_entry.get() )
power_lower_entry.delete( 0, tkinter.END )
power_upper_entry.delete( 0, tkinter.END )
assert x1<=x2
power_scaler.config( from_ = x1, to = x2 )
except :
power_lower_entry.delete( 0, tkinter.END )
power_upper_entry.delete( 0, tkinter.END )
tkinter.messagebox.showwarning( "Add Powers", "Add valid numbers!" )
def add_value_fn():
x1 = int( coef_scaler.get() )
x2 = int( power_scaler.get() )
coef_entry.insert( tkinter.END, str(x1) + ',' )
power_entry.insert( tkinter.END, str(x2) + ',' )
def delete_value_fn():
try:
power_array = list( power_entry.get()[:-1].split(',') )
coef_array = list( coef_entry.get()[:-1].split(',') )
#print(len(power_array))
power_entry.delete( 0, tkinter.END )
coef_entry.delete( 0, tkinter.END )
assert power_array[0] != ''
for i in range( len( power_array ) - 1 ):
power_entry.insert( tkinter.END, power_array[i] + ',')
for i in range( len( coef_array ) - 1 ):
coef_entry.insert( tkinter.END, coef_array[i]+',')
except:
tkinter.messagebox.showwarning( "Delete Variables", "No values to delete!" )
def restart_fn():
power_entry.delete( 0, tkinter.END )
coef_entry.delete( 0, tkinter.END )
coef_scaler.config( from_ = -1000, to = 1000 )
power_scaler.config( from_ = -10, to = 10 )
fig=Figure(figsize=( 5, 5 ), dpi = 48 )
plot=fig.add_subplot( 111 )
canvas=FigureCanvasTkAgg( fig, master = root )
canvas.draw()
canvas.get_tk_widget().place( x = 420, y = 129 )
def plot_fn():
try:
y=np.zeros( 80 )
x=np.arange( 1, 21, 0.25 )
power_array = list(map(int , power_entry.get()[:-1].split(',') ))
coef_array = list(map(int , coef_entry.get()[:-1].split(',') ))
for i in range(len( power_array ) ):
ones = np.arange( 1, 21, 0.25 )
if power_array[i] >= 0 :
ones = pow( ones, power_array[i] )
else:
ones = negpow( ones, power_array[i] )
ones = ones * coef_array[i]
y = np.add( y, ones )
fig=Figure(figsize=( 5 , 5 ), dpi = 48 )
plot=fig.add_subplot( 111 )
plot.plot( x, y )
canvas=FigureCanvasTkAgg( fig, master = root )
canvas.draw()
canvas.get_tk_widget().place( x = 420, y = 129 )
except:
tkinter.messagebox.showwarning( 'Graphly', 'Add valid values!' )
#Header --------------------------------------------------------------------------------
root = tkinter.Tk()
root.title( 'Graphly4.0.1' )
root.geometry( "700x470" )
root.config(bg = 'lightskyblue')
# EntryBoxes ---------------------------------------------------------------------------
coef_entry = tkinter.Entry( root, width = 90 )
power_entry = tkinter.Entry( root, width = 90 )
coef_lower_entry = tkinter.Entry( root, width = 10 )
coef_upper_entry = tkinter.Entry( root, width = 10 )
power_lower_entry = tkinter.Entry( root, width = 10 )
power_upper_entry = tkinter.Entry( root, width = 10 )
# Labels --------------------------------------------------------------------------------
heading = tkinter.Label(root,text='❄︎❄︎❄︎GRAPHLY ❄︎❄︎❄︎', bg = 'lightskyblue', font = ( "Courier", 20 ) )
coef_label = tkinter.Label( root, text = 'Coefficient Values' , bg = 'lightskyblue' )
power_label = tkinter.Label( root, text = 'Power Values' , bg = 'lightskyblue')
coef_heading = tkinter.Label( root, text = 'Set Coefficient Value', bg = 'lightskyblue' )
power_heading = tkinter.Label( root, text = 'Set Power Value', bg = 'lightskyblue' )
coef_from = tkinter.Label( root, text = 'Lower Value', bg = 'lightskyblue' )
coef_to = tkinter.Label( root, text = 'Upper Value', bg = 'lightskyblue' )
power_from = tkinter.Label( root, text = 'Lower Value', bg = 'lightskyblue' )
power_to = tkinter.Label( root, text = 'Upper Value', bg = 'lightskyblue' )
see_figure_label = tkinter.Label( root, text = 'See Figure Down Here' )
# Scales ---------------------------------------------------------------------------------
coef_scaler = tkinter.Scale( root, from_ = -1000, to = 1000,
orient = tkinter.HORIZONTAL, length = 200,
bg = 'royalblue', highlightbackground = 'royalblue',
activebackground = 'mediumblue', trough = 'deepskyblue')
power_scaler = tkinter.Scale( root, from_ = -10, to = 10 ,
orient = tkinter.HORIZONTAL, length = 200,
bg = 'royalblue', highlightbackground = 'royalblue',
activebackground = 'mediumblue', trough = 'deepskyblue')
# Buttons --------------------------------------------------------------------------------
coef_apply_button = tkinter.Button( root, text = ' Apply',
height = 1, width = 6,
command = coef_apply_fn,
bg = 'royalblue', bd = 4 )
power_apply_button = tkinter.Button( root, text = ' Apply',
height = 1, width = 6,
command = power_apply_fn,
bg = 'royalblue', bd = 4 )
add_value_button = tkinter.Button( root, text = 'Add \nValue',
height = 3, width = 9,
command = add_value_fn,
bg = 'royalblue', bd = 4 )
delete_value_button = tkinter.Button( root, text = 'Delete \nValue',
height = 3, width = 9,
command = delete_value_fn,
bg = 'royalblue', bd = 4 )
restart_button = tkinter.Button( root, text = 'Restart',
height = 3, width = 9,
command = restart_fn,
bg = 'royalblue', bd = 4 )
exit_button = tkinter.Button( root, text = 'Exit',
height = 3, width = 9,
command = Exit,
bg = 'royalblue', bd = 4 )
plot_button = tkinter.Button( root, text = 'PLOT',
height = 5, width = 40,
command =plot_fn,
bg = 'aqua', bd = 4 )
# Plaecholders ----------------------------------------------------------------------------
heading.place( x = 90, y = 20)
coef_label.place( x = 10, y = 70 )
power_label.place( x = 34, y = 100 )
coef_entry.place( x = 115, y = 70 )
power_entry.place( x = 115, y = 100 )
coef_heading.place( x = 180, y = 150 )
coef_from.place( x = 20, y = 170 )
coef_lower_entry.place( x = 100, y = 170 )
coef_to.place( x = 20, y = 190 )
coef_upper_entry.place( x = 100, y = 190 )
coef_scaler.place( x = 170, y = 170 )
coef_apply_button.place( x = 20, y = 210 )
power_heading.place( x = 190, y = 260 )
power_from.place( x = 20, y = 280)
power_lower_entry.place( x = 100, y = 280 )
power_to.place( x = 20, y = 300 )
power_upper_entry.place( x = 100, y = 300 )
power_scaler.place( x = 170, y = 280 )
power_apply_button.place( x = 20, y = 320 )
add_value_button.place( x = 20, y = 390 )
delete_value_button.place( x = 112, y = 390 )
exit_button.place( x = 204, y = 390 )
restart_button.place( x = 296, y = 390 )
plot_button.place( x = 400, y = 376 )
# Canvas -----------------------------------------------------------------------------------
fig=Figure(figsize = (5, 5), dpi = 48)
plot=fig.add_subplot(111)
canvas=FigureCanvasTkAgg(fig, master = root)
canvas.draw()
canvas.get_tk_widget().place(x = 420, y = 129)
root.mainloop()