Advertisement
peth31

Corrección Barra de Colores

Jun 26th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import matplotlib.colors as colors
  2.  
  3. class MidpointNormalize(colors.Normalize):
  4.     """
  5.     Normalise the colorbar so that diverging bars work there way either side from a prescribed midpoint value)
  6.  
  7.     e.g. im=ax1.imshow(array, norm=MidpointNormalize(midpoint=0.,vmin=-100, vmax=100))
  8.     """
  9.     def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
  10.         self.midpoint = midpoint
  11.         colors.Normalize.__init__(self, vmin, vmax, clip)
  12.  
  13.     def __call__(self, value, clip=None):
  14.         # I'm ignoring masked values and all kinds of edge cases to make a
  15.         # simple example...
  16.         x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
  17.         return np.ma.masked_array(np.interp(value, x, y), np.isnan(value))
  18.  
  19. elev_min=30 #Define el valor mínimo de la barra de colores
  20. elev_max=46 #Define el valor máximo de la barra de colores
  21. mid_val= 35 #Define el valor medio/ la mitad de la barra de colores
  22. rango = np.arange(elev_min,elev_max, 1.0) #Define el rango de la barra de colores y c/cuanto
  23.  
  24.  
  25. ####### Aquí se pone el rango y el resto del código para que funcione la barra ajustada y no se mueva
  26. m.contourf(x,y,data,rango,cmap='hot_r', clim=(elev_min, elev_max), norm=MidpointNormalize
  27.                 (midpoint=mid_val,vmin=elev_min, vmax=elev_max))
  28. #######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement