Changeset 687 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jan 28, 2016, 1:38:11 PM (9 years ago)
Author:
lfita
Message:

Adding linewithds and linepoints on `ColorsLinesPointsStyles?'
Adding `markerevery' on 'plot_lines_time'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing.py

    r684 r687  
    18131813      ncfilens= [filen] ',' separated list of netCDF files
    18141814      values= [dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];[timevals];[locleg];
    1815         [graphk];[collines];[points];[pointfreq];[period]
     1815        [graphk];[collines];[points];[linewidths];[pointsizes];[pointfreq];[period]
    18161816        [dimvname]: ',' list of names of the variables with he values of the common dimension
    18171817        [valuesaxis]: which axis will be used for the values ('x', or 'y')
     
    18411841        [points]: ',' list of type of points for the lines, None for automatic, single
    18421842          value all the same
     1843        [linewidths]: ',' list of widths for the lines, None for automatic, single
     1844          value all the same
     1845        [pointsizes]: ',' list of widths for the lines, None for automatic, single
     1846          value all the same
    18431847        [pointfreq]: frequency of point plotting, 'all' for all time steps
    18441848        [period]: which period to plot
     
    18581862    expectargs = '[dimvname];[valuesaxis];[dimtit];[leglabels];[vtit];[title];'
    18591863    expectargs = expectargs + '[timevals];[locleg];[graphk];[lines];[collines];[points];'
    1860     expectargs = expectargs + '[pointfreq];[period]'
     1864    expectargs = expectargs + '[linewidths];[pointsizes];[pointfreq];[period]'
    18611865    drw.check_arguments(fname,len(expectargs.split(';')),values,';',expectargs)
    18621866
     
    18741878    collines0 = values.split(';')[10]
    18751879    points0 = values.split(';')[11]
    1876     pointfreq0 = values.split(';')[12]
    1877     period = values.split(';')[13]
     1880    linewidths0 = values.split(';')[12]
     1881    pointsizes0 = values.split(';')[13]
     1882    pointfreq0 = values.split(';')[14]
     1883    period = values.split(';')[15]
    18781884
    18791885    Nfiles = len(ncfiles)
     
    19041910    if collines0.find(',') != -1:
    19051911        collines = collines0.split(',')
    1906     elif collines == 'None':
     1912    elif collines0 == 'None':
    19071913        collines = None
    19081914    else:
     
    19201926        for ip in range(Nfiles):
    19211927            points.append(points0)
     1928
     1929# Multiple line sizes?
     1930    if linewidths0.find(',') != -1:
     1931        linewidths = []
     1932        Nlines = len(linewidths0.split(','))
     1933        for il in Nlines:
     1934          linewidths.append(np.float(linewidths0.split(',')[il]))
     1935    elif linewidths0 == 'None':
     1936        linewidths = None
     1937    else:
     1938        linewidths = [np.float(linewidths0)]
     1939
     1940# Multiple point sizes?
     1941    if pointsizes0.find(',') != -1:
     1942        pointsizes = []
     1943        Npts = len(pointsizes0.split(','))
     1944        for ip in Npts:
     1945          pointsizes.append(np.float(pointsizes0.split(',')[ip]))
     1946    elif pointsizes0 == 'None':
     1947        pointsizes = None
     1948    else:
     1949        pointsizes = [np.float(pointsizes0)]
    19221950
    19231951# Getting values
     
    20622090    drw.plot_lines_time(dimvalues, varvalues, valuesaxis, dimtit, legvals, vartit,   \
    20632091      varunits, timepos, timelabels, title, locleg, graphk, lines, collines, points, \
    2064       pointfreq)
     2092      linewidths, pointsizes, pointfreq)
    20652093
    20662094    return
  • trunk/tools/drawing_tools.py

    r684 r687  
    1717fillValueF = 1.e20
    1818
     19colorsauto = ['#FF0000', '#00FF00', '#0000FF', '#FF00FF', '#00FFFF', '#FFAA00',     \
     20  '#AA0000', '#00AA00', '#0000AA', '#AA00AA', '#00AAAA', '#AA3200']
    1921pointkindsauto = ['.', ',', 'x', '+', '*', '|', '_', 'o', '<', '>', 'v', '^',       \
    2022  's', 'D', 'p' ,'h' ,'H']
    2123linekindsauto = ['-', '--', '-.', ':']
     24linewidthsauto = [1.]
     25pointsizesauto = [7.]
    2226
    2327####### Funtions
     
    53995403    return
    54005404
     5405def ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq):
     5406    """ Function to provide the colors, lines & points styles
     5407      Nstyles= total number of styles
     5408      colors= list of colors, None for no value
     5409      lines= list of lines, None for no value
     5410      points= list of points, None for no value
     5411      lwidths= list of line widths, None for no value
     5412      psizes= list of point sizes, None for no value
     5413      ptfreq= frequency for the points, None for all values
     5414    >>> Nstyles = 3
     5415    >>> colors = ['blue']
     5416    >>> lines = ['-']
     5417    >>> points = ['x', '*', 'o']
     5418    >>> lwidths = ['1']
     5419    >>> psizes = ['2']
     5420    >>> ptfreq = 2
     5421    >>> colors, lines, points = ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq)
     5422    ['blue', 'blue', 'blue']
     5423    ['-', '-', '-']
     5424    ['x', '*', 'o']
     5425    ['2', '2', '2']
     5426    ['1', '1', '1']
     5427    """
     5428    fname = 'ColorsLinesPointsStyles'
     5429
     5430    usecolors = []
     5431    uselines = []
     5432    usepoints = []
     5433    usewlines = []
     5434    usespoints = []
     5435
     5436# Colors
     5437    if colors is None:
     5438        Ncols = len(colorsauto)
     5439        for ic in range(Nstyles):
     5440            iic = np.mod(ic,Ncols) - 1
     5441            if iic == 0: iic = Ncols - 1
     5442            usecolors.append(colorsauto[iic])
     5443    else:
     5444        Ncols = len(colors)
     5445        if Ncols == 1:
     5446            for ic in range(Nstyles):
     5447                usecolors.append(colors[0])
     5448        else:
     5449            if Ncols != Nstyles:
     5450                print errormsg
     5451                print '  ' + fname + ': number of provided colors:', Ncols,          \
     5452                  'and required:', Nstyles,'differ !!'
     5453                quit(-1)
     5454            usecolors = colors
     5455
     5456# Lines
     5457    if lines is None:
     5458        Nklns = len(linekindsauto)
     5459        for il in range(Nstyles):
     5460            iil = np.mod(il,Nklns) - 1
     5461            if iil == 0: iil = Nklns - 1
     5462            uselines.append(linekindsauto[iil])
     5463    else:
     5464        Nklns = len(lines)
     5465        if Nklns == 1:
     5466            for il in range(Nstyles):
     5467                uselines.append(lines[0])
     5468        else:
     5469            if Nklns != Nstyles:
     5470                print errormsg
     5471                print '  ' + fname + ': number of provided lines:', Nklns,           \
     5472                  'and required:', Nstyles,'differ !!'
     5473                quit(-1)
     5474            uselines = lines
     5475
     5476# Points
     5477    if points is None:
     5478        Nkpts = len(pointkindsauto)
     5479        for ip in range(Nstyles):
     5480            iip = np.mod(ip,Nkpts) - 1
     5481            if iip == 0: iip = Nkpts - 1
     5482            usepoints.append(pointkindsauto[iip])
     5483    else:
     5484        Nkpts = len(points)
     5485        if Nkpts == 1:
     5486            for ip in range(Nstyles):
     5487                usepoints.append(points[0])
     5488        else:
     5489            if Nkpts != Nstyles:
     5490                print errormsg
     5491                print '  ' + fname + ': number of provided points:', Nkpts,          \
     5492                  'and required:', Nstyles,'differ !!'
     5493                quit(-1)
     5494            usepoints = points
     5495
     5496# Line widths
     5497    if lwidths is None:
     5498        Nwlns = len(linewidthsauto)
     5499        for il in range(Nstyles):
     5500            iil = np.mod(il,Nwlns) - 1
     5501            if iil == 0: iil = Nwlns - 1
     5502            usewlines.append(linewidthsauto[iil])
     5503    else:
     5504        Nwlns = len(lwidths)
     5505        if Nwlns == 1:
     5506            for il in range(Nstyles):
     5507                usewlines.append(lwidths[0])
     5508        else:
     5509            if Nwlns != Nstyles:
     5510                print errormsg
     5511                print '  ' + fname + ': number of provided line widthss:', Nwlns,    \
     5512                  'and required:', Nstyles, 'differ !!'
     5513                quit(-1)
     5514            usewlines = lwidths
     5515
     5516# Point sizes
     5517    if psizes is None:
     5518        Nspts = len(pointsizesauto)
     5519        for ip in range(Nstyles):
     5520            iip = np.mod(ip,Nspts) - 1
     5521            if iip == 0: iip = Nspts - 1
     5522            usespoints.append(pointsizesauto[iip])
     5523    else:
     5524        Nspts = len(psizes)
     5525        if Nspts == 1:
     5526            for ip in range(Nstyles):
     5527                usespoints.append(psizes[0])
     5528        else:
     5529            if Nspts != Nstyles:
     5530                print errormsg
     5531                print '  ' + fname + ': number of provided point sizes:', Nspts,     \
     5532                  'and required:', Nstyles, 'differ !!'
     5533                quit(-1)
     5534            usespoints = psizes
     5535
     5536    Ncols = len(usecolors)
     5537    Nlins = len(uselines)
     5538    Npnts = len(usepoints)
     5539
     5540    lkinds = []
     5541    pkinds = []
     5542
     5543    lcolors = usecolors
     5544
     5545# Old way
     5546#    if ptfreq is not None:
     5547#        lkinds = uselines
     5548#        pkinds = usepoints
     5549#    else:
     5550#        pkinds = usepoints
     5551#        lkinds = uselines
     5552#        for ilp in range(Nstyles):
     5553#            lkinds.append(usepoints[ilp] + uselines[ilp])
     5554           
     5555    return lcolors, uselines, usepoints, usewlines, usespoints
     5556
     5557#Nstyles = 3
     5558#colors = ['blue']
     5559#lines = ['-']
     5560#points = ['x', '*', 'o']
     5561#lwidths = ['2']
     5562#psizes = ['1']
     5563#ptfreq = 2
     5564#print ColorsLinesPointsStyles(Nstyles, colors, lines, points, lwidths, psizes, ptfreq)
     5565
    54015566def LinesPointsStyles(Nstyles, lines, points, ptfreq):
    54025567    """ Function to provide the lines & points styles
     
    54635628        pkinds = usepoints
    54645629    else:
     5630        pkinds = usepoints
    54655631        for ilp in range(Nstyles):
    54665632            lkinds.append(usepoints[ilp] + uselines[ilp])
     
    54695635
    54705636def plot_lines_time(vardv, varvv, vaxis, dtit, linesn0, vtit, vunit, tpos, tlabs,    \
    5471   gtit, gloc, kfig, lsl, coll, ptl, ptf):
     5637  gtit, gloc, kfig, lsl, coll, ptl, lwidth, psize, ptf):
    54725638    """ Function to plot a collection of lines with a time axis
    54735639      vardv= list of set of dimension values
     
    54915657      ptl= ',' list of type of points for the lines, None for automatic, single
    54925658          value all the same
     5659      lwidth= ',' list of line widths
     5660      psize= ',' list of point sizes
    54935661      ptf= frequency of point plotting, 'all' for all time steps
    5494  
     5662
    54955663      plot_lines([np.arange(10)], [np.sin(np.arange(10)*np.pi/2.5)], 'y', 'time (s)',      \
    54965664  ['2.5'], 'sin', '-', 'sinus frequency dependency', 'pdf')
     
    55055673    Ntraj = len(vardv)
    55065674
    5507     linekinds, pointkinds = LinesPointsStyles(Ntraj, lsl, ptl, ptf)
     5675    colvalues, linekinds, pointkinds, lwidths, psizes = ColorsLinesPointsStyles(     \
     5676      Ntraj, coll, lsl, ptl, lwidth, psize,  ptf)
    55085677
    55095678    plt.rc('text', usetex=True)
     
    55225691    if vaxis == 'x':
    55235692        for il in range(Ntraj):
    5524             if coll is None:
    5525                 if ptf is None:
    5526                     plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il])
    5527                 else:
    5528                     plt.plot(varvv[il], vardv[il], linekinds[il])
    5529                     plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il],     \
    5530                       label= linesn[il])
    5531             else:
    5532                 if ptf is None:
    5533                     plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il], \
    5534                       color=coll[il])
    5535                 else:
    5536                     plt.plot(varvv[il], vardv[il], linekinds[il], color=coll[il])
    5537                     plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il],     \
    5538                       label= linesn[il], color=coll[il])
     5693            plt.plot(varvv[il], vardv[il], linekinds[il], marker=pointkinds[il],     \
     5694              label=linesn[il], color=colvalues[il], linewidth=lwidths[il],          \
     5695              markersize=psizes[il], markevery=ptf)
     5696
     5697# Old way
     5698#            if ptf is None:
     5699#                plt.plot(varvv[il], vardv[il], linekinds[il], label= linesn[il],     \
     5700#                  color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il])
     5701#            else:
     5702#                plt.plot(varvv[il], vardv[il], linekinds[il], color=colvalues[il],   \
     5703#                  linewidth=lwidths[il])
     5704#                plt.plot(varvv[il][::ptf], vardv[il][::ptf], pointkinds[il],         \
     5705#                  label= linesn[il], color=colvalues[il], linewidth=lwidths[il],     \
     5706#                  markersize=psizes[il])
    55395707
    55405708            minvv = np.min(varvv[il])
     
    55585726    else:
    55595727        for il in range(Ntraj):
    5560             if coll is None:
    5561                 if ptf is None:
    5562                     plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il])
    5563                 else:
    5564                     plt.plot(vardv[il], varvv[il], linekinds[il])
    5565                     plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il],     \
    5566                       label= linesn[il])
    5567             else:
    5568                 if ptf is None:
    5569                     plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il], \
    5570                       color=coll[il])
    5571                 else:
    5572                     plt.plot(vardv[il], varvv[il], linekinds[il], color=coll[il])
    5573                     plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il],      \
    5574                       label= linesn[il], color=coll[il])
     5728            plt.plot(vardv[il], varvv[il], linekinds[il], marker=pointkinds[il],     \
     5729              label=linesn[il], color=colvalues[il], linewidth=lwidths[il],          \
     5730              markersize=psizes[il], markevery=ptf)
     5731
     5732# Old way
     5733#            if ptf is None:
     5734#                plt.plot(vardv[il], varvv[il], linekinds[il], label= linesn[il],     \
     5735#                  color=colvalues[il], linewidth=lwidths[il], markersize=psizes[il], markevery=ptf)
     5736#            else:
     5737#                plt.plot(vardv[il], varvv[il], linekinds[il], color=coll[il],        \
     5738#                  linewidth=lwidths[il])
     5739#                plt.plot(vardv[il][::ptf], varvv[il][::ptf], pointkinds[il],         \
     5740#                  label= linesn[il], color=colvalues[il], linewidth=lwidths[il],     \
     5741#                  markersize=psizes[il])
    55755742
    55765743            minvv = np.min(varvv[il])
Note: See TracChangeset for help on using the changeset viewer.