Changeset 2364 in lmdz_wrf


Ignore:
Timestamp:
Feb 22, 2019, 7:33:44 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `draw_MerPara': Function to add the parallels and meridians into a figure with a panel of plots
  • Enhancing `NcolNrow_figure' with how plot meridians and parallels
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/drawing_tools.py

    r2363 r2364  
    125125# check_colorBar: Check if the given colorbar exists in matplotlib
    126126# colorbar_vals: Function to provide the colorbar values for a figure
     127# draw_MerPara: Function to add the parallels and meridians into a figure with a
     128#   panel of plots
    127129# figureMap_size: Function to determine the real size of a figure adjusted to the
    128130#   ratio of the maps
     
    160162# multi_plot_2D_shadow: plot of multiple 2D shadowing variables sharing colorbar
    161163# NcolNrow_figure: Function to provide the number of rows and columns for a panel of
    162 #   figures always more rows than columns
     164#   figures always more rows than columns and to provide where to draw meridians and
     165#   parallels
    163166# pixelgrid: Function to provide the kind of grid distribution for a plot
    164167# plot_points:
     
    31073110    return figsizev, txtlineh
    31083111
    3109 def NcolNrow_figure(Npanels):
     3112def NcolNrow_figure(Npanels, kind='squared'):
    31103113    """ Function to provide the number of rows and columns for a panel of figures
    3111         always more rows than columns
     3114        and to provide where to draw meridians and parallels
    31123115      Npanels: number of panels to be included in the figure
     3116      kind: kind of panel distribution
     3117        'squared': equal columns and rows as: Ncol=sqrt(Npanels), Nrow=Npanels/Ncol+1
     3118           (default). Always more rows than columns
     3119        'colfix',[Ncol]: fixing [Ncol] number of columns
     3120        'rowfix',[Nrow]: fixing [Nrow] number of rows
     3121      Returns:
     3122        [Ncol], [Nrow], [NOpanels], [meridians], [parallels]
     3123        Ncol: number of columns
     3124        Nrow: number of rows
     3125        NOpanels: list with coordinates from axis matrix without assigned plot
     3126        meridians: list of values wether meridians should be labelled left, right,
     3127          or not labelled at all
     3128        parallels: list of values wether parallels should be labelled bottom, top,
     3129          or not labelled at all
    31133130    >>> NcolNrow_figure(10)
    3114     3, 4, [[3, 1], [3, 2]]
     3131    3, 4, [[3, 1], [3, 2]], ['top', 'top', 'top', 'top', 'no', 'no', 'no', 'no',
     3132      'bottom', 'bottom', 'bottom', 'bottom'], ['left', 'no', 'no', 'right', 'left',
     3133      'no', 'no', 'right', 'left', 'no', 'no', 'right']
    31153134    """
    31163135    fname = 'NcolNrow_figure'
    31173136
    3118     Ncol = int(np.sqrt(Npanels))
    3119     Nrow = Npanels / Ncol + 1
    3120 
    3121     if Ncol > Nrow:
    3122         Ncol0 = Ncol + 0
    3123         Ncol = Nrow + 0
    3124         Nrow = Ncol0
     3137    availkind = ['squared', "'colfix',[Ncol]", "'rowfix',[Nrow]"]
     3138
     3139    if kind == 'squared':
     3140        Ncol = int(np.sqrt(Npanels))
     3141        Nrow = Npanels / Ncol + 1
     3142        if Ncol > Nrow:
     3143            Ncol0 = Ncol + 0
     3144            Ncol = Nrow + 0
     3145            Nrow = Ncol0
     3146    elif kind[0:6] == 'colfix':
     3147        Ncol = int(kind.split(',')[1])
     3148        Nrow = Npanels/Ncol
     3149        if Ncol*Nrow < Npanels: Nrow = Nrow+1
     3150    elif kind[0:6] == 'rowfix':
     3151        Nrow = int(kind.split(',')[1])
     3152        Ncol = Npanels/Nrow
     3153        if Ncol*Nrow < Npanels: Ncol = Ncol+1
     3154    else:
     3155        print errormsg
     3156        print '  ' +fname+ ": kind of panel distribution '" + kind + "' not ready !!"
     3157        print '    available ones:', availkind
     3158        quit(-1)
    31253159
    31263160    # panel array without draw
    31273161    NOpanels = []
     3162    meridians = []
     3163    parallels = []
    31283164    panels = np.arange(Ncol*Nrow).reshape(Nrow,Ncol)
    31293165    ipanel = 0
     
    31333169            ipanel = ipanel + 1
    31343170
    3135     return Ncol, Nrow, NOpanels
     3171            if ir == 0: parallels.append('left')
     3172            elif ir == Nrow-1: parallels.append('right')
     3173            else: parallels.append('no')
     3174
     3175            if ic == 0: meridians.append('top')
     3176            elif ic == Ncol-1: meridians.append('bottom')
     3177            else: meridians.append('no')
     3178
     3179    return Ncol, Nrow, NOpanels, meridians, parallels
    31363180
    31373181#print NcolNrow_figure(10)
     3182
     3183def draw_MerPara(mape, mers, pars, ip, Ncol, Nrow, fsize=8, rotmer=0, rotpar=0,      \
     3184  col='#080808'):
     3185    """ Function to add the parallels and meridians into a figure with a panel of
     3186       plots
     3187     map: basemap map environtment
     3188     mers: list of meridians to plot
     3189     pars: list of parallels to plot
     3190     ip: plot number (0, starting)
     3191     Ncol: number of columns
     3192     Nrow: number of rows
     3193     fsize: size of labels (8 default)
     3194     rotmer: angle of ratation of the labels of the meridians
     3195     rotpar: angle of ratation of the labels of the parallels
     3196     col: color of lines ('#080808' default)
     3197    """
     3198    fname = 'draw_MerPara'
     3199
     3200    # Parallels
     3201    if np.mod(ip,Ncol) == 0:
     3202        mape.drawparallels(pars,labels=[True,False,False,True], fontsize=fsize,      \
     3203          color=col, rotation=rotpar)
     3204    elif np.mod(ip+1,Ncol) == 0:
     3205        mape.drawparallels(pars,labels=[False,True,True,False], fontsize=fsize,      \
     3206          color=col, rotation=rotpar)
     3207    else:
     3208        mape.drawparallels(pars,labels=[False,False,False,False], fontsize=fsize,    \
     3209          color=col, rotation=rotpar)
     3210
     3211    if ip+1 > (Nrow-1)*Ncol:
     3212        mape.drawmeridians(mers, labels=[True,False,False,True], fontsize=fsize,     \
     3213          color=col, rotation=rotmer)
     3214# NO on top meridians
     3215#    elif ip+1 < Ncol:
     3216#        mape.drawmeridians(mers, labels=[False,True,True,False], fontsize=fsize,     \
     3217#          color=col, rotation=rotmer)
     3218    else:
     3219        mape.drawmeridians(mers, labels=[False,False,False,False], fontsize=fsize,   \
     3220          color=col, rotation=rotmer)
     3221
     3222    return
    31383223
    31393224####### ###### ##### #### ### ## # END of GENERIC functions
Note: See TracChangeset for help on using the changeset viewer.