Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/03/2013, 13:50
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Duda con kwargs.pop()

1.- Tu error no esta en la linea 15
2.- El método pop de los diccionarios no esta relacionado a tu problema.
3.- Tu problema esta en la linea 48 falla cuando el array esta lleno de ceros, no validas bien ese caso.

Código Python:
Ver original
  1. from __future__ import unicode_literals
  2.  
  3. import numpy as np
  4. from numpy import ma
  5. from matplotlib import scale as mscale
  6. from matplotlib import transforms as mtransforms
  7. from matplotlib.ticker import Formatter, FixedLocator
  8.  
  9. class EscalaAcumuladaGumbel(mscale.ScaleBase):
  10.  
  11.     name = 'gumbel'
  12.  
  13.     def __init__(self, axis, **kwargs):
  14.         mscale.ScaleBase.__init__(self)
  15.         umbral = kwargs.pop("umbral", 0.9999)
  16.         if not (0 < umbral < 1.0):
  17.             raise ValueError("umbral debe ser mayor que 0.0 o menor que 1.0")
  18.         self.umbral = umbral
  19.  
  20.     def get_transform(self):
  21.         return self.TransformacionAcumuladaGumbel(self.umbral)
  22.  
  23.     def set_default_locators_and_formatters(self, axis):
  24.         class TresDecimales(Formatter):
  25.             def __call__(self, x, pos=None):
  26.                 return '%.3f' % x
  27.         axis.set_major_locator(FixedLocator(np.arange(0.0, 1.0, 0.05)))
  28.         axis.set_major_formatter(TresDecimales())
  29.         axis.set_minor_formatter(TresDecimales())
  30.  
  31.     def limit_range_for_scale(self, vmin, vmax, minpos):
  32.         return max(vmin, -self.umbral), min(vmax, self.umbral)
  33.  
  34.     class TransformacionAcumuladaGumbel(mtransforms.Transform):
  35.         input_dims = 1
  36.         output_dims = 1
  37.         is_separable = True
  38.  
  39.         def __init__(self, umbral):
  40.             mtransforms.Transform.__init__(self)
  41.             self.umbral = umbral
  42.  
  43.         def transform(self, a):
  44.             masked = ma.masked_where((a < -self.umbral) | (a > self.umbral), a)
  45.             if masked.mask.any():
  46.                 return 0.156516164484 + (0.0915834783405*(-ma.log(-ma.log(a))))
  47.             else:
  48.                 if not np.all(a):
  49.                     a = np.empty(a.size)
  50.                     a.fill(.9999)
  51.                 return 0.156516164484 + (0.0915834783405*(-np.log(-np.log(a))))
  52.  
  53.         def inverted(self):
  54.             return EscalaAcumuladaGumbel.TransformacionInversaAcumuladaGumbel(self.umbral)
  55.  
  56.     class TransformacionInversaAcumuladaGumbel(mtransforms.Transform):
  57.         input_dims = 1
  58.         output_dims = 1
  59.         is_separable = True
  60.  
  61.         def __init__(self, umbral):
  62.             mtransforms.Transform.__init__(self)
  63.             self.umbral = umbral
  64.  
  65.         def transform(self, a):
  66.             return np.exp(-np.exp(-a))
  67.  
  68.         def inverted(self):
  69.             return EscalaAcumuladaGumbel.TransformacionAcumuladaGumbel(self.umbral)
  70.  
  71. mscale.register_scale(EscalaAcumuladaGumbel)
  72.  
  73.  
  74. if __name__ == '__main__':
  75.     import matplotlib.pyplot as plt
  76.  
  77.     Datos = np.array([ 2690.0, 2700.0, 2700.667, 2701.333, 2702.0, 3196.0, 2372.0, 2395.0, 2128.0, 2727.0, 2431.0, 2850.0, 2216.0, 2057.0, 2269.0, 2208.0, 2628.0, 2729.0, 2588.0, 3448.0, 2508.0, 3081.0, 2417.0, 2770.0, 2283.0, 2455.0, 1963.0, 2786.0, 2885.0, 2357.0, 3422.0, 2423.0, 2148.0, 1305.0, 2472.0, 2186.0, 2720.0, 2430.0, 2304.0, 2556.0, 2625.0, 2164.0, 2585.0, ])
  78.     DatosOrdenados = np.sort(Datos)
  79.     mu = 2353.157
  80.     sigma = 297.961
  81.  
  82.     y1 = ( DatosOrdenados - mu) / sigma
  83.     x1 = np.exp(-np.exp(-y1))
  84.  
  85.     plt.plot(x1, y1, 'ro', lw=2)
  86.     plt.gca().set_xscale('gumbel')
  87.  
  88.     plt.xlabel('F(z)')
  89.     plt.ylabel('z')
  90.     plt.title('Papel de probabilidad de Gumbel')
  91.     plt.xticks(rotation='vertical', fontsize=7)
  92.     plt.grid(True)
  93.  
  94.     plt.show()