Changeset 1263 in lmdz_wrf for trunk


Ignore:
Timestamp:
Nov 2, 2016, 10:38:04 PM (9 years ago)
Author:
lfita
Message:

Adding the use of `dimxyfmt' on 'Nlines'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r1259 r1263  
    21142114    draw_lines(ncfilens, values, varname):
    21152115      ncfilens= [filen] ',' separated list of netCDF files
    2116       values= [dimvname]:[valuesaxis]:[dimtit]:[leglabels]:[vtit]:[title]:[legvals]:[colns]:[lines]
     2116      values= [dimvname]:[valuesaxis]:[dimtit]:[dimxyfmt]:[leglabels]:[vtit]:[title]:[legvals]:[colns]:[lines]
    21172117       [points]:[lwdths]:[psizes]:[freqv]:[figname]:[graphk]:[close]
    21182118        [dimvname]: ',' list of names of the variable with he values of the common dimension
    21192119        [valuesaxis]: which axis will be used for the values ('x', or 'y')
    21202120        [dimtit]: title for the common dimension
    2121         [leglabels]: ',' separated list of names for the legend
     2121        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordx]: format of the values at each axis (or 'auto')
     2122          [dxs]: style of x-axis ('auto' for 'pretty')
     2123            'Nfix', values computed at even 'Ndx'
     2124            'Vfix', values computed at even 'Ndx' increments
     2125            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     2126          [dxf]: format of the labels at the x-axis ('auto' for '%5g')
     2127          [Ndx]: Number of ticks at the x-axis ('auto' for 5)
     2128          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     2129          [dys]: style of y-axis ('auto' for 'pretty')
     2130          [dyf]: format of the labels at the y-axis ('auto' for '%5g')
     2131          [Ndy]: Number of ticks at the y-axis ('auto' for 5)
     2132          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     2133        [leglabels]: ',' separated list of names for the legend ('!' for spaces)
    21222134        [vartit]: name of the variable in the graph
    21232135        [title]: title of the plot ('|' for spaces)
     
    21482160        quit()
    21492161
    2150     expectargs = '[dimvname]:[valuesaxis]:[dimtit]:[leglabels]:[vtit]:[title]:' +    \
    2151       '[legvals]:[colns]:[lines]:[points]:[lwdths]:[psizes]:[freqv]:[figname]:' +    \
    2152       '[graphk]:[close]'
     2162    expectargs = '[dimvname]:[valuesaxis]:[dimtit]:[dimxyfmt]:[leglabels]:[vtit]:' + \
     2163      '[title]:[legvals]:[colns]:[lines]:[points]:[lwdths]:[psizes]:[freqv]:' +      \
     2164      '[figname]:[graphk]:[close]'
    21532165    drw.check_arguments(fname,values,expectargs,':')
    21542166
     
    21572169    valuesaxis = values.split(':')[1]
    21582170    dimtit = values.split(':')[2]
    2159     leglabels = gen.latex_text(values.split(':')[3])
    2160     vartit = values.split(':')[4]
    2161     title = values.split(':')[5].replace('|',' ')
    2162     legvals = values.split(':')[6]
    2163     colns = gen.str_list(values.split(':')[7], ',')
    2164     lines = gen.str_list(values.split(':')[8], ',')
    2165     points = gen.str_list(values.split(':')[9], '@')
    2166     lwdths = gen.str_list_k(values.split(':')[10], ',', 'R')
    2167     psizes = gen.str_list_k(values.split(':')[11], ',', 'R')
    2168     freqv0 = values.split(':')[12]
    2169     figname = values.split(':')[13]
    2170     graphk = values.split(':')[14]
    2171     close = gen.Str_Bool(values.split(':')[15])
     2171    dimxyfmt = values.split(':')[3]
     2172    leglabels = gen.latex_text(values.split(':')[4].replace('!',' '))
     2173    vartit = values.split(':')[5]
     2174    title = values.split(':')[6].replace('|',' ')
     2175    legvals = values.split(':')[7]
     2176    colns = gen.str_list(values.split(':')[8], ',')
     2177    lines = gen.str_list(values.split(':')[9], ',')
     2178    points = gen.str_list(values.split(':')[10], '@')
     2179    lwdths = gen.str_list_k(values.split(':')[11], ',', 'R')
     2180    psizes = gen.str_list_k(values.split(':')[12], ',', 'R')
     2181    freqv0 = values.split(':')[13]
     2182    figname = values.split(':')[14]
     2183    graphk = values.split(':')[15]
     2184    close = gen.Str_Bool(values.split(':')[16])
    21722185
    21732186    Nfiles = len(ncfiles)
     
    22512264    locleg, legfontsize = drw.legend_values(legvals,'|')
    22522265
    2253     drw.plot_lines(dimvalues, varvalues, valuesaxis, dimtit, leglabels.split(','),   \
    2254       vartit, varunits, title, locleg, legfontsize, colns, lines, points, lwdths,    \
    2255       psizes, freqv, figname, graphk, close)
     2266    # axis
     2267    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
     2268    xaxis = [xstyl, xaxf, Nxax, xaxor]
     2269    yaxis = [ystyl, yaxf, Nyax, yaxor]
     2270
     2271    drw.plot_lines(dimvalues, varvalues, valuesaxis, dimtit, xaxis, yaxis,           \
     2272      leglabels.split(','), vartit, varunits, title, locleg, legfontsize, colns,     \
     2273      lines, points, lwdths, psizes, freqv, figname, graphk, close)
    22562274
    22572275    return
  • trunk/tools/drawing_tools.py

    r1253 r1263  
    18031803    same = ['1', 'category', 'day', 'deg', 'degree', 'degrees', 'degrees East',      \
    18041804      'degrees Nord', 'degrees North', 'g', 'gpm', 'hour', 'hPa', 'K', 'Km', 'kg',   \
    1805       'km', 'm', 'minute', 'mm', 'month', 'Pa', 's', 'second', 'um', 'year', '-']
     1805      'km', 'm', 'minute', 'mm', 'month', 'Pa', 's', 'second', 'um', 'x', 'y',       \
     1806      'year', '-']
    18061807
    18071808    if searchInlist(same,u):
     
    56985699    return
    56995700
    5700 def plot_lines(vardv, varvv, vaxis, dtit, linesn, vtit, vunit, gtit, gloc, gsiz, cs, \
    5701   ls, ps, ws, ss, fv, fign, kfig, ifclose):
     5701def plot_lines(vardv, varvv, vaxis, dtit, xaxv, yaxv, linesn, vtit, vunit, gtit,    \
     5702  gloc, gsiz, cs, ls, ps, ws, ss, fv, fign, kfig, ifclose):
    57025703    """ Function to plot a collection of lines
    57035704      vardv= list of set of dimension values
     
    57055706      vaxis= which axis will be used for the values ('x', or 'y')
    57065707      dtit= title for the common dimension
     5708      xaxv= list with the x-axis paramteres [style, format, number and orientation]
     5709      yaxv= list with the y-axis paramteres [style, format, number and orientation]
    57075710      linesn= names for the legend
    57085711      vtit= title for the vaxis
     
    57335736        quit()
    57345737
    5735 # Canging line kinds every 7 lines (end of standard colors)
     5738    # Axis ticks
     5739    # Usually axis > x must be the dimension, thus...
     5740    dxn = np.min(vardv)
     5741    dxx = np.max(vardv)
     5742    dyn = np.min(varvv)
     5743    dyx = np.max(varvv)
     5744
     5745    if xaxv[0] == 'pretty':
     5746        dimxt0 = np.array(gen.pretty_int(dxn,dxx,xaxv[2]))
     5747    elif xaxv[0] == 'Nfix':
     5748        dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
     5749    elif xaxv[0] == 'Vfix':
     5750        dimxt0 = np.arange(0,dxx,xaxv[2])
     5751    if yaxv[0] == 'pretty':
     5752        dimyt0 = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
     5753    elif yaxv[0] == 'Nfix':
     5754        dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
     5755    elif yaxv[0] == 'Vfix':
     5756        dimyt0 = np.arange(0,dyx,yaxv[2])
     5757
     5758    dimxv0 = dimxt0
     5759    dimyv0 = dimyt0
     5760
     5761    dimxl0 = []
     5762    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1]))
     5763    dimyl0 = []
     5764    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1]))
     5765
     5766    dimxT0 = gen.latex_text(dtit)
     5767    dimyT0 = gen.latex_text(vtit) + ' (' + units_lunits(vaxis) + ')'
     5768
     5769    pixkind = 'fixpixel'
     5770
     5771    if vaxis == 'y':
     5772        reva = None
     5773    else:
     5774        reva = 'transpose'
     5775
     5776    if reva is not None:
     5777        varsv = np.zeros((len(dimxt0), len(dimyt0)), dtype=np.float)
     5778        varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT =              \
     5779          transform(varsv, reva, dxv=dimxv0, dyv=dimyv0, dxt=dimxt0, dyt=dimyt0,     \
     5780          dxl=dimxl0, dyl=dimyl0, dxtit=dimxT0, dytit=dimyT0)
     5781    else:
     5782        dimxv = dimxv0
     5783        dimyv = dimyv0
     5784        dimxt = dimxt0
     5785        dimyt = dimyt0
     5786        dimxl = dimxl0
     5787        dimyl = dimyl0
     5788        dimxT = dimxT0
     5789        dimyT = dimyT0
     5790
    57365791    Ntraj = len(vardv)
    5737 
     5792    # Lines' characteristics
    57385793    cols, lins, pts, lws, pss = ColorsLinesPointsStyles(Ntraj, cs, ls, ps, ws, ss, fv)
    5739 
    5740     xmin = 100000.
    5741     xmax = -100000.
    5742     ymin = 100000.
    5743     ymax = -100000.
    5744     for il in range(Ntraj):
    5745         minv = np.min(varvv[il])
    5746         maxv = np.max(varvv[il])
    5747         mind = np.min(vardv[il])
    5748         maxd = np.max(vardv[il])
    5749 
    5750         if minv < xmin: xmin = minv
    5751         if maxv > xmax: xmax = maxv
    5752         if mind < ymin: ymin = mind
    5753         if maxd > ymax: ymax = maxd
    57545794
    57555795    plt.rc('text', usetex=True)
     
    57605800              linewidth=lws[il], markersize=pss[il], label= linesn[il], color=cols[il])
    57615801
    5762         plt.xlabel(gen.latex_text(vtit) + ' (' + units_lunits(vunit) + ')')
    5763         plt.ylabel(dtit)
    5764         plt.xlim(xmin,xmax)
    5765         plt.ylim(ymin,ymax)
     5802        plt.xlim(dyn,dyx)
     5803        plt.ylim(dxn,dxx)
    57665804
    57675805    else:
     
    57695807            plt.plot(vardv[il], varvv[il], lins[il], marker=pts[il],                 \
    57705808              linewidth=lws[il], markersize=pss[il], label= linesn[il], color=cols[il])
    5771 
    5772         plt.xlabel(dtit)
    5773         plt.ylabel(gen.latex_text(vtit) + ' (' + units_lunits(vunit) + ')')
    57745809       
    5775         plt.xlim(ymin,ymax)
    5776         plt.ylim(xmin,xmax)
     5810        plt.xlim(dxn,dxx)
     5811        plt.ylim(dyn,dyx)
     5812
     5813    plt.xlabel(dimxT)
     5814    plt.ylabel(dimyT)
     5815    plt.xticks(dimxt, dimxl, rotation=xaxv[3])
     5816    plt.yticks(dimyt, dimyl, rotation=yaxv[3])
    57775817
    57785818    graphtit = gen.latex_text(gtit)
     
    62816321    dimxl0 = []
    62826322    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i],        \
    6283         style=xaxv[1]))
     6323        style=xaxv[1])) 
    62846324    dimyl0 = []
    62856325    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i],        \
Note: See TracChangeset for help on using the changeset viewer.