Changeset 1147 in lmdz_wrf for trunk/tools/drawing_tools.py


Ignore:
Timestamp:
Oct 6, 2016, 3:04:05 PM (8 years ago)
Author:
lfita
Message:

Adding dxdyfmt', colorbarvalues' and `close' in 'draw_2D_shad_cont'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r1134 r1147  
    18501850        elif u == 'ms-2': lu='$ms^{-2}$'
    18511851        elif u == 'minutes': lu='$minute$'
     1852        elif u == 'meters MSL': lu='$m$'
     1853        elif u == 'none': lu='-'
    18521854        elif u == 'Pa/s': lu='$Pas^{-1}$'
    18531855        elif u == 'Pas-1': lu='$Pas^{-1}$'
     
    27092711    rangegrph = np.zeros((2), dtype=np.float)
    27102712# Changing limits of the colors
    2711     if type(vrng[0]) != type(np.float(1.)) and type(vrng[0]) != type(np.float64(1.)):
     2713    if vrng[0][0:1] == 'S':
    27122714        if vrng[0] == 'Srange':
    27132715            rangegrph[0] = np.min(varsV)
     
    27652767        print '    ' + fname + ': modified shadow min,max:',rangegrph
    27662768    else:
    2767         rangegrph[0] = vrng[0]
    2768         rangegrph[1] = vrng[1]
     2769        rangegrph[0] = np.float(vrng[0])
     2770        rangegrph[1] = np.float(vrng[1])
    27692771
    27702772    return rangegrph
     
    44434445    return
    44444446
    4445 def plot_2D_shadow_contour(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,          \
    4446   colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv):
     4447def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv,   \
     4448  yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig,    \
     4449  reva, mapv, ifclose):
    44474450    """ Adding labels and other staff to the graph
    44484451      varsv= 2D values to plot with shading
     
    44514454      dim[x/y]v = values at the axes of x and y
    44524455      dim[x/y]u = units at the axes of x and y
     4456      xaxv= list with the x-axis paramteres [style, format, number and orientation]
     4457      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    44534458      dimn= dimension names to plot
    44544459      colorbar= name of the color bar to use
     4460      cbarfmt= format of the numbers in the colorbar
     4461      cbaror= orientation of the colorbar
    44554462      ckind= contour kind
    44564463        'cmap': as it gets from colorbar
     
    44774484          * 'h', high
    44784485          * 'f', full
     4486      ifclose= boolean value whether figure should be close (finish) or not
    44794487    """
    44804488##    import matplotlib as mpl
     
    44884496        quit()
    44894497
     4498    if len(varsv.shape) != 2:
     4499        print errormsg
     4500        print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
     4501        quit(-1)
     4502    if len(varcv.shape) != 2:
     4503        print errormsg
     4504        print '  ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!'
     4505        quit(-1)
     4506
     4507    # Axis ticks
    44904508    # Usually axis > x must be the lon, thus...
    44914509    dimxv0 = dimxv.copy()
    44924510    dimyv0 = dimyv.copy()
    4493     dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10))
    4494     dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10))
     4511
     4512    dxn = dimxv.min()
     4513    dxx = dimxv.max()
     4514    dyn = dimyv.min()
     4515    dyx = dimyv.max()
     4516
     4517    if xaxv[0] == 'pretty':
     4518        dimxt0 = np.array(pretty_int(dxn,dxx,xaxv[2]))
     4519    elif xaxv[0] == 'Nfix':
     4520        dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
     4521    elif xaxv[0] == 'Vfix':
     4522        dimxt0 = np.arange(0,dxx,xaxv[2])
     4523    if yaxv[0] == 'pretty':
     4524        dimyt0 = np.array(pretty_int(dyn,dyx,yaxv[2]))
     4525    elif yaxv[0] == 'Nfix':
     4526        dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
     4527    elif yaxv[0] == 'Vfix':
     4528        dimyt0 = np.arange(0,dyx,yaxv[2])
     4529
    44954530    dimxl0 = []
    4496     for i in range(len(dimxt0)): dimxl0.append('{:.1f}'.format(dimxt0[i]))
     4531    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1]))
    44974532    dimyl0 = []
    4498     for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i]))
     4533    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1]))
     4534
    44994535    dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
    45004536    dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
     
    45924628
    45934629    else:
    4594         x,y = gen.lonlat2D(dimxv,dimyv)
     4630        # No following data values
     4631        #x = dimxv
     4632        #y = dimyv
     4633        x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
     4634        y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
    45954635
    45964636    plt.rc('text', usetex=True)
    45974637
    45984638    plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1])
    4599     cbar = plt.colorbar()
     4639    if cbaror == 'horizontal':
     4640        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4641        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
     4642        ticklabels= cbar.ax.get_xticklabels()
     4643        Nticks = len(ticklabels)
     4644        ticklabs = []
     4645        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
     4646        cbar.ax.set_xticklabels(ticklabs,rotation=90)
     4647    else:
     4648        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
    46004649
    46014650# contour
     
    46384687        plt.ylabel(dimyT)
    46394688
    4640         plt.xticks(dimxt, dimxl)
    4641         plt.yticks(dimyt, dimyl)
     4689        plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     4690        plt.yticks(dimyt, dimyl, rotation=yaxv[3])
    46424691
    46434692# set the limits of the plot to the limits of the data
     
    46464695
    46474696# units labels
    4648     cbar.set_label(vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')')
    4649     plt.annotate(vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' +  \
     4697    cbar.set_label(gen.latex_text(vnames[0]) + ' (' + units_lunits(uts[0]) + ')')
     4698    plt.annotate(gen.latex_text(vnames[1]) +' (' + units_lunits(uts[1]) + ') [' +  \
    46504699      mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction',    \
    46514700      color=coln)
    46524701
    46534702    figname = '2Dfields_shadow-contour'
    4654     graphtit = vtit.replace('_','\_').replace('&','\&')
     4703    graphtit = gen.latex_text(vtit)
    46554704
    46564705    plt.title(graphtit)
    46574706   
    4658     output_kind(kfig, figname, True)
     4707    output_kind(kfig, figname, ifclose)
    46594708
    46604709    return
Note: See TracChangeset for help on using the changeset viewer.