In [2]:
#Diego Javier Mena Amado -20092005053
import numpy as num
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plot
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.backend_bases import key_press_handler
import scipy.constants as spc
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
home = Tk.Tk()
home.wm_title("Ecuacion del limite de Wien")
#Declaracion de limites
f = Figure()
plota = f.add_subplot(111)
#Declaracion de Variables
a = num.linspace(0, 7, 10001)#variable del eje x
b = 1-num.exp(-a)-a/5#Funcion
#Proceso de calculo de cuando x=0;
zero=1
coef=0
for i in range(1,10001):
if b[i]>0:
if b[i]<zero:
zero=b[i]
coef=i
#t contiene el valor cuando x=0
t=a[coef]
#Se les asigna el label correspondiente a cada eje
plota.plot(a,b,label=r'$F(x)=1-\exp{(-x)}-\frac{1}{5}x$')
plota.set_xlabel(r'$x=\frac{hc}{\lambda KT}$')
plota.set_ylabel(r'F(x)',rotation='horizontal')
plota.legend(loc=3)
plota.axis([0, 7,-0.6,0.6])
#Graficacion del punto de x=0
plota.plot([t, t], [0, 0.48], color='blue', linewidth=2.5, linestyle="--")
plota.scatter([t, ], [0.48, ], 50, color='blue')
plota.annotate(t,xy=(t,0.5), xycoords='data',xytext=(+1, +1), textcoords='offset points', fontsize=16)
# Muestra la grafica-------------------------------------------------
plota.set_title('Ecuacion del limite de Wien')
f.tight_layout()
plota.grid(True)
canvas = FigureCanvasTkAgg(f,master=home)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg(canvas, home)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
#Proceso de seleccion del teclado
R = "right"
L = "left"
x = 5
var = Tk.StringVar()
label = Tk.Label(home, textvariable=var, fg="black", bg="white", font = "Helvetica 14 bold italic")
var.set("Utilice las flechas horizontales del teclado para desplazarce por la grafica")
def on_key_event(event):
if event.key==R:
global a
global b
global x
x = x + 0.125
if x<0.125:
x = 0.125
y = 1-num.exp(-x)-x/5
pass
else:
y = 1-num.exp(-x)-x/5
if x>6.875:
x = 6.875
y = 1-num.exp(-x)-x/5
pass
else:
y = 1-num.exp(-x)-x/5
n = num.linspace(x,x,2)
plota.cla()
plota.plot(a,b,label=r'$F(x)=1-\exp{(-x)}-\frac{1}{5}x$')
plota.legend(loc=3)
plota.set_xlabel(r'$x=\frac{hc}{\lambda KT}$')
plota.set_ylabel(r'"F(x)',rotation='horizontal')
plota.axis([0, 7,-0.6,0.6])
plota.plot([t, t], [0, 0.48], color='blue', linewidth=2.5, linestyle="--")
plota.scatter([t, ], [0.48, ], 50, color='blue')
plota.annotate(t,xy=(t,0.5), xycoords='data',xytext=(+1, +1), textcoords='offset points', fontsize=16)
# Muestra la grafica-------------------------------------------------
plota.set_title('Ecuacion del limite de Wien')
f.tight_layout()
plota.grid(True)
plota.scatter([x, ], [y, ], 50, color='blue')
canvas.draw()
var.set("Valores sobre la curva\t F(x)= "+str(y)+" con x= "+str(x))
elif event.key==L:
global a
global b
global x
x = x - 0.125
if x<0.125:
x = 0.125
y = 1-num.exp(-x)-x/5
pass
else:
y = 1-num.exp(-x)-x/5
if x>6.875:
x = 6.875
y = 1-num.exp(-x)-x/5
pass
else:
y = 1-num.exp(-x)-x/5
n = num.linspace(x,x,2)
plota.cla()
plota.plot(a,b,label=r'$F(x)=1-\exp{(-x)}-\frac{1}{5}x$')
plota.legend(loc=3)
plota.set_xlabel(r'$x=\frac{hc}{\lambda KT}$')
plota.set_ylabel(r'F(x)',rotation='horizontal')
plota.axis([0, 7,-0.6,0.6])
plota.plot([t, t], [0, 0.48], color='blue', linewidth=2.5, linestyle="--")
plota.scatter([t, ], [0.48, ], 50, color='blue')
plota.annotate(t,xy=(t,0.5), xycoords='data',xytext=(+1, +1), textcoords='offset points', fontsize=16)
# Muestra la grafica-------------------------------------------------
plota.set_title('Ecuacion del limite de Wien')
f.tight_layout()
plota.grid(True)
plota.scatter([x, ], [y, ], 50, color='blue')
canvas.draw()
var.set("Valores sobre la curva\t F(x) = "+str(y)+" con x= "+str(x))
else:
pass
key_press_handler(event, canvas, toolbar)
canvas.mpl_connect('key_press_event', on_key_event)
label.pack(side="bottom", ipady=20)
#Continue el proceso
Tk.mainloop()
In [ ]:
In [ ]: