Changeset 2603 in lmdz_wrf


Ignore:
Timestamp:
Jun 14, 2019, 5:37:52 PM (6 years ago)
Author:
lfita
Message:

Adding label characteristics in `drawpolygon_map'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r2600 r2603  
    1444914449    return mapv
    1445014450
    14451 def drawpolygon_map(vertices, mape, polylab, Nint, linev):
     14451def drawpolygon_map(vertices, mape, polylabv, Nint, linev):
    1445214452    """ Function to plot a polygon into a map
    1445314453      vertices: Matrix of vertices of the polygon [[lon1,lat1], ..., [lonM,latM]]
    1445414454      mape: basemap map environtment where to draw the polygon
    14455       polylab: label of the polygon (already LaTeX freindly)
     14455      polylabv: [polylab, color, size, face, angle, pos]: values for the label of
     14456          the polygon
     14457        polylab: label of the polygon (already LaTeX freindly, None for no label)
     14458        color: color of the characters
     14459        size: size of the font
     14460        face: weight of the letters
     14461          'normal': normal face
     14462          'bold': bold face
     14463        angle: angle of roation
     14464        pos: position as:
     14465          'c': center
     14466          'vert',Nvert: at coordinates of vertex number Nvert
     14467          'overt',xoffset,yoffset: at coordinates of vertex number Nvert aplying an
     14468            offset at each direction
    1445614469      Nint: number of intermediate grid points to use in order to have lon, lat
    1445714470        following polygon borders
     
    1445914472    """
    1446014473    fname = 'drawpolygon_map'
     14474    availpolylabpos = ['c', "'vert',Nvert", "'osw',xoffset,yoffset"]
    1446114475
    1446214476    Lvert = vertices.shape[0]
     
    1448014494            if iv == 0 and ij == 0:
    1448114495                plt.plot([pptii[ij],pptii[ij+1]],[pptjj[ij],pptjj[ij+1]], linev[2],  \
    14482                   color=linev[0], linewidth=linev[1], label=polylab)
     14496                  color=linev[0], linewidth=linev[1], label=polylabv[0])
    1448314497            else:
    1448414498                plt.plot([pptii[ij],pptii[ij+1]],[pptjj[ij],pptjj[ij+1]], linev[2],  \
     
    1450314517          color=linev[0], linewidth=linev[1])
    1450414518
     14519    # Label location
     14520    polylab = polylabv[0]
     14521    if polylab is not None:
     14522        polylabpos = polylabv[5].split(',')
     14523        if polylabpos[0] == 'c':
     14524            xlabp = np.sum(vertices[:,0])
     14525            ylabp = np.sum(vertices[:,1])
     14526        elif polylabpos[0] == 'vert':
     14527            iv = int(polylabpos[1])
     14528            if iv > Lvert:
     14529                print errormsg
     14530                print '  ' + fname + ": provided vertex ", iv, 'is too large for ' + \
     14531                  'polygon with ', Lvert, 'vertices !!'
     14532                quit(-1)
     14533            xlabp = vertices[iv,0]
     14534            ylabp = vertices[iv,1]
     14535        elif polylabpos[0] == 'overt':
     14536            iv = int(polylabpos[1])
     14537            if iv > Lvert:
     14538                print errormsg
     14539                print '  ' + fname + ": provided vertex ", iv, 'is too large for ' + \
     14540                  'polygon with ', Lvert, 'vertices !!'
     14541                quit(-1)
     14542            xlabp = vertices[iv,0] + np.float(polylabpos[2])
     14543            ylabp = vertices[iv,1] + np.float(polylabpos[3])
     14544        else:
     14545            print errormsg
     14546            print '  ' + fname + ": position of the label '" + polylabpos[0] +       \
     14547              "' not available !!"
     14548            print '    available ones:', availpolylabpos
     14549            quit(-1)
     14550
     14551        if polylabv[3] == 'normal':       
     14552            plt.annotate(polylab, xy=(xlabp,ylabp), xycoords='data',                 \
     14553              color=polylabv[1], fontsize=polylabv[2], rotation=polylabv[4])
     14554        else:
     14555            plt.annotate(polylab, xy=(xlabp,ylabp), xycoords='data',                 \
     14556              color=polylabv[1], fontsize=polylabv[2], weight=polylabv[3],           \
     14557              rotation=polylabv[4])
     14558
     14559        print 'Lluis ' + fname + ': polylab', polylab, 'xy pos', xlabp, ylabp
     14560 
    1450514561    return
Note: See TracChangeset for help on using the changeset viewer.