In [19]:
import numpy as np
#import pyfirmata as pyF
from time import sleep
import os
import matplotlib.pyplot as plt
%matplotlib inline
from scipy import stats
from scipy import constants as cons
'''

#####################################
## COMUNICACION
#####################################
port = 'com5'
board = pyF.Arduino(port)

it = pyF.util.Iterator(board)               #Estas lineas garantizan comunicacion con la tarjeta.
it.start()
'''


######################################
##VECTORES
######################################
led=[1.6325,2.424,2.566,3.7095]
lamb=[1.10e6,1.60514e6,1.70648e6,2.14133e6]

IR=np.loadtxt("datos_IR.dat")
Red=np.loadtxt("datos_rojo.dat")
#Blue=np.loadtxt("datos_azul.dat")
Green=np.loadtxt("datos_verde.dat")
Orange=np.loadtxt("datos_naranja.dat")


volt_IR=IR[:,0]
volt_red=Red[:,0]
volt_red=volt_red*(3.3/5.)
#volt_blue=Blue[:,0]
volt_green=Green[:,0]
volt_orange=Orange[:,0]


curr_IR=IR[:,1]
curr_red=Red[:,1]
#curr_blue=Blue[:,1]
curr_green=Green[:,1]
curr_orange=Orange[:,1]


curr_red*=(3.3/5.)
Vred=[]
Ired=[]
for i in range(len(curr_red)):
    if (volt_red[i]>1.716):
        if (volt_red[i]<=3.28053):
            Vred.append(volt_red[i])
            Ired.append(curr_red[i])
            print (volt_red[i],curr_red[i])


1.79025 0.005181
1.84833 0.00523908
1.90971 0.00530772
1.96449 0.00532686
2.03214 0.00539616
2.08065 0.00539616
2.1483 0.00549318
2.20011 0.00549384
2.27403 0.00549318
2.33541 0.00553278
2.40009 0.00557172
2.46114 0.00557106
2.52252 0.00558096
2.60337 0.00567006
2.69676 0.0056892
2.76144 0.0056991
2.82249 0.00571824
2.91951 0.00576774
3.02907 0.00575784
3.12576 0.00577698
3.28053 0.0058839

In [36]:
led=[1.6325,2.424,2.566,3.24050,3.7095]
led=np.array(led)
led*=(3.3/5.)
lamb=[1.10e6,1.60514e6,1.70648e6,1.76367e6,2.14133e6]
lamb=np.array(lamb)
lamb*=(3.3/5.)
slope, intercept, r_value, p_value, std_err = stats.linregress(lamb,led)
x=np.linspace(lamb[0],lamb[-1],100)
y=slope*x+intercept
plt.plot(lamb,led,'o')
plt.plot(x,y,'-')
plt.show()
h_planck=slope*cons.e/cons.c
h=cons.h
error=(h_planck-h)/h
print ('r: ',r_value)
print ('pendiente: ',slope)
print ('error: ',std_err)
print ('h_planck: ',h_planck)
print ('h_real: ',h)
print ('error_h: ',error)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-36-2666440c87c7> in <module>()
      9 y=slope*lamb+intercept
     10 plt.plot(lamb,led,'o')
---> 11 plt.plot(x,y,'-')
     12 plt.show()
     13 h_planck=slope*cons.e/cons.c

/usr/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   3316                       mplDeprecation)
   3317     try:
-> 3318         ret = ax.plot(*args, **kwargs)
   3319     finally:
   3320         ax._hold = washold

/usr/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1890                     warnings.warn(msg % (label_namer, func.__name__),
   1891                                   RuntimeWarning, stacklevel=2)
-> 1892             return func(ax, *args, **kwargs)
   1893         pre_doc = inner.__doc__
   1894         if pre_doc is None:

/usr/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
   1404         kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
   1405 
-> 1406         for line in self._get_lines(*args, **kwargs):
   1407             self.add_line(line)
   1408             lines.append(line)

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
    405                 return
    406             if len(remaining) <= 3:
--> 407                 for seg in self._plot_args(remaining, kwargs):
    408                     yield seg
    409                 return

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
    383             x, y = index_of(tup[-1])
    384 
--> 385         x, y = self._xy_from_xy(x, y)
    386 
    387         if self.command == 'plot':

/usr/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
    242         if x.shape[0] != y.shape[0]:
    243             raise ValueError("x and y must have same first dimension, but "
--> 244                              "have shapes {} and {}".format(x.shape, y.shape))
    245         if x.ndim > 2 or y.ndim > 2:
    246             raise ValueError("x and y can be no greater than 2-D, but have "

ValueError: x and y must have same first dimension, but have shapes (100,) and (5,)

In [28]:
plt.plot(Vred,Ired,'bo')

pendiente, intercepto, r_value, p_value, std_err = stats.linregress(Vred,Ired)
yred=[]
VActivacion_rojo=intercepto*330
for i in Vred:
    yred.append((pendiente*i)+intercepto)
plt.plot(Vred,yred,'-')

print (led[1],VActivacion_rojo)


2.424 1.48745682735