Changeset 2714 in lmdz_wrf for trunk


Ignore:
Timestamp:
Sep 27, 2019, 5:27:16 PM (5 years ago)
Author:
lfita
Message:

Adding:

  • `fixedvalues_cbar': Function to provide a color bar atr fixed values and colors
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r2713 r2714  
    170170# figureMap_size: Function to determine the real size of a figure adjusted to the
    171171#   ratio of the maps
     172# fixedvalues_cbar: Function to provide a color bar atr fixed values and colors
    172173# format_axes: Function to provide the format for the ticks of the axes in a figure
    173174# graphic_range: Function to provide the ranges of a figure following different options
     
    1466514666    return
    1466614667
     14668def fixedvalues_cbar(fixvalbnds, RGBfixvalcolors):
     14669    """ Function to provide a color bar atr fixed values and colors
     14670      fixvalues: list values at a given color
     14671      RGBfixvalcolors: list of colors
     14672    >>> vals=[-140., 0., 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000., \
     14673      1500., 2000., 3000., 4000., 7000.]
     14674    >>> colors = [[119,152,93], [149,181,112], [189,209,137], [233,238,154],         \
     14675      [248,242,168], [251,231,163], [252,225,144], [248,213,133], [251,189,141],     \
     14676      [231,175,139], [202,149,132], [206,156,149], [228,182,192], [250,214,231],     \
     14677      [224,224,224], [255,255,255], [255,255,255]]
     14678    >>> fixedvalues_cbar(vals, colors)
     14679    """
     14680    fname = 'fixedvalues_cbar'
     14681
     14682    if len(fixvalbnds) != len(RGBfixvalcolors):
     14683        Nbnds = len(fixvalbnds)
     14684        Ncls = len(RGBfixvalcolors)
     14685        print errormsg
     14686        print '  ' + fname + ': number of values:', Nbnds, 'and number of colors',   \
     14687          Ncls, 'differ !!'
     14688        print '      passed values & colors _______'
     14689        if Nbnds > Ncls:
     14690            for i in range(Ncls):
     14691                print '      ', i, fixvalbnds[i], RGBfixvalcolors[i]
     14692            for i in range(Ncls,Nbnds):
     14693                print '      ', i, fixvalbnds[i]
     14694        else:
     14695            for i in range(Nbnds):
     14696                print '      ', i, fixvalbnds[i], RGBfixvalcolors[i]
     14697            for i in range(Nbnds,Ncls):
     14698                print '      ', i, '--', RGBfixvalcolors[i]
     14699        quit(-1)
     14700
     14701    # Srting values
     14702    bndsS = []
     14703    for b in fixvalbnds: bndsS.append(str(b))
     14704
     14705    HEXfixvalcolors = []
     14706    Nfixvalcolors = len(RGBfixvalcolors)
     14707    for ic in range(Nfixvalcolors):
     14708        rgbv = np.array(RGBfixvalcolors[ic], dtype=np.float)/255.
     14709        rgbv = np.where(rgbv > 0.1, rgbv - 0.1, 0.)
     14710        if np.all(rgbv == 0.9): rgbv = rgbv/0.9
     14711
     14712        hexcol = gen.coldec_hex(rgbv)
     14713        HEXfixvalcolors.append(hexcol)
     14714
     14715    fixvalcmap = mpl.colors.ListedColormap(HEXfixvalcolors)
     14716    fixvalnormc = mpl.colors.BoundaryNorm(fixvalbnds, fixvalcmap.N)
     14717
     14718    return bndsS, fixvalcmap, fixvalnormc
     14719
Note: See TracChangeset for help on using the changeset viewer.