Changeset 1123 in lmdz_wrf


Ignore:
Timestamp:
Sep 30, 2016, 4:47:55 PM (9 years ago)
Author:
lfita
Message:

Adding [orientation]' for the colorbar which becomes a new variable [colorbarvals]' in draw_2D_shad

  • Rotating tick-labels in colorbar if this is orientated 'horixzontally'
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1120 r1123  
    5656    draw_2D_shad(ncfile, values, varn)
    5757      ncfile= file to use
    58       values=[vnamefs]:[dimvals]:[dimxvn]:[dimyvn]:[colorbar]:[fmtcolorbar]:[sminv],[smaxv]:[figt]:
     58      values=[vnamefs]:[dimvals]:[dimxvn]:[dimyvn]:[colorbarvals]:[sminv],[smaxv]:[figt]:
    5959       [kindfig]:[reverse]:[mapv]:[close]
    6060        [vnamefs]: Name in the figure of the variable to be shaded
     
    6262          variable a given value is required (-1, all the length)
    6363        [dimx/yvn]: name of the variables with the values of the final dimensions (x,y)
    64         [colbarn]: name of the color bar
    65         [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
     64        [colorbarvals]=[colbarn],[fmtcolorbar],[orientation]
     65          [colorbarn]: name of the color bar
     66          [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
     67          [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal')
    6668        [smin/axv]: minimum and maximum value for the shading or:
    6769          'Srange': for full range
     
    101103        quit()
    102104
    103     expectargs = '[vnamefs]:[dimvals]:[dimxvn]:[dimyvn]:[colbarn]:[fmtcolorbar]:' +  \
     105    expectargs = '[vnamefs]:[dimvals]:[dimxvn]:[dimyvn]:[colbarvals]:' +             \
    104106      '[sminv],[smaxv]:[figt]:[kindfig]:[reverse]:[mapv]:[close]'
    105107 
     
    110112    vdimxn = values.split(':')[2]
    111113    vdimyn = values.split(':')[3]
    112     colbarn = values.split(':')[4]
    113     fmtcolbar0 = values.split(':')[5]
    114     shadminmax = values.split(':')[6]
    115     figtitle = values.split(':')[7].replace('|',' ')
    116     figkind = values.split(':')[8]
    117     revals = values.split(':')[9]
    118     mapvalue = values.split(':')[10]
    119     close = gen.Str_Bool(values.split(':')[11])
     114    colorbarvals = values.split(':')[4]
     115    shadminmax = values.split(':')[5]
     116    figtitle = values.split(':')[6].replace('|',' ')
     117    figkind = values.split(':')[7]
     118    revals = values.split(':')[8]
     119    mapvalue = values.split(':')[9]
     120    close = gen.Str_Bool(values.split(':')[10])
    120121
    121122    ncfiles = ncfile
     
    224225    if mapvalue == 'None': mapvalue = None
    225226
     227    colbarn = colorbarvals.split(',')[0]
     228    fmtcolbar0 = colorbarvals.split(',')[1]
     229    colbaror0 = colorbarvals.split(',')[2]
     230
    226231    if fmtcolbar0 == 'auto':
    227         fmtcolorbar = '%6g'
    228     else:
    229         fmtcolorbar = fmtcolbar0
     232        fmtcolbar = '%6g'
     233    else:
     234        fmtcolbar = fmtcolbar0
     235    if colbaror0 == 'auto':
     236        colbaror = 'vertical'
     237    else:
     238        colbaror = colbaror0
     239
    230240
    231241    drw.plot_2D_shadow(valshad, vnamesfig, odimxv, odimyv, odimxu, odimyu, dimnamesv,\
    232       colbarn, fmtcolorbar, shading_nx, varunits, figtitle, figkind, revals,        \
     242      colbarn, fmtcolbar, colbaror, shading_nx, varunits, figtitle, figkind, revals, \
    233243      mapvalue, close)
    234244
  • trunk/tools/drawing_tools.py

    r1120 r1123  
    37773777
    37783778def plot_2D_shadow(varsv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,          \
    3779   colorbar,cbarfmt,vs,uts,vtit,kfig,reva,mapv,ifclose):
     3779  colorbar,cbarfmt,cbaror,vs,uts,vtit,kfig,reva,mapv,ifclose):
    37803780    """ Adding labels and other staff to the graph
    37813781      varsv= 2D values to plot with shading
     
    37863786      colorbar= name of the color bar to use
    37873787      cbarfmt= format of the numbers in the colorbar
     3788      cbaror= orientation of the colorbar
    37883789      vs= minmum and maximum values to plot in shadow or:
    37893790        'Srange': for full range
     
    40014002
    40024003    plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vsend[0], vmax=vsend[1])
    4003     cbar = plt.colorbar(format=cbarfmt)
     4004    if cbaror == 'horizontal':
     4005        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4006        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
     4007        ticklabels= cbar.ax.get_xticklabels()
     4008        Nticks = len(ticklabels)
     4009        ticklabs = []
     4010        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
     4011        cbar.ax.set_xticklabels(ticklabs,rotation=90)
     4012    else:
     4013        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
     4014   
    40044015
    40054016    if not mapv is None:
Note: See TracChangeset for help on using the changeset viewer.