-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetodo_grafico.py
More file actions
73 lines (55 loc) · 2 KB
/
metodo_grafico.py
File metadata and controls
73 lines (55 loc) · 2 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
import numpy as np
import customtkinter as ctk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from obtener_matrices import obtener_datos
def funcion_lineal(x_1, coef_a, coef_b, coef_c):
y = (coef_c - coef_b*x_1)/coef_a
return y
def funcion_constante_y(x, const_a, const_b):
const = const_b/const_a
return np.full(x.shape, const)
def constructor_grafico(matrix_A, vect_b):
coefientes_x_y = []
x = np.linspace(0, 20, 1000)
for i in matrix_A:
for j in i[range(0,2)]:
coefientes_x_y.append(j)
fig = plt.Figure(figsize=(6, 4), dpi=100)
ax = fig.add_subplot(111)
ax.set_xlim(0, 20)
ax.set_ylim(-1, 20)
for i in range(1,len(coefientes_x_y), 2):
if coefientes_x_y[i] == 0:
# caso y = 0
ax.vlines(x = vect_b[int((i-1)/2)], ymin = 0, ymax = max(x), colors = 'purple')
elif coefientes_x_y[i-1] == 0:
# caso x = 0
y_x0 = funcion_constante_y(x, coefientes_x_y[i], vect_b[int((i-1)/2)])
ax.plot(x, y_x0)
else:
y = funcion_lineal(x, coefientes_x_y[i], coefientes_x_y[i-1], vect_b[int((i-1)/2)])
ax.plot(x, y)
ax.grid(True)
print(coefientes_x_y)
return fig
def mostrar_grafica(num_columnas, entradas, filas):
c, A, b, tiene_solucion = obtener_datos(num_columnas, entradas, filas)
print("c")
print(c)
print("A")
print(A)
print("b")
print(b)
print("tiene_solución")
print(tiene_solucion)
# Crear una nueva ventana Toplevel
ventana_grafica = ctk.CTkToplevel()
fig = constructor_grafico(A, b)
# Crear un objeto FigureCanvasTkAgg para mostrar la figura en la ventana
canvas = FigureCanvasTkAgg(fig, master=ventana_grafica)
canvas.draw()
# Agregar el widget Canvas a la ventana
canvas.get_tk_widget().pack()
# Configurar la ventana y otros widgets si es necesario
ventana_grafica.title("Gráfica del problema")