Index: /trunk/tools/drawing.py
===================================================================
--- /trunk/tools/drawing.py	(revision 1146)
+++ /trunk/tools/drawing.py	(revision 1147)
@@ -10,5 +10,5 @@
 ## e.g. # drawing.py -f /media/data2/etudes/WRF_LMDZ/WL_HyMeX/IIphase/medic950116/wlmdza/wrfout/wrfout_d01_1995-01-13_00:00:00 -o create_movie -S 'draw_2D_shad#Time@WRFTimes@10@95@191@1#tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:None' -v T2
 ## e.g. # drawing.py -f wrfout_d01_1980-03-01_00\:00\:00_Time_B0-E48-I1.nc -o draw_2D_shad -S 'tas:East_West|-1,North_South|-1,Time|2:longitude:latitude:Summer:270.,300.:tas|at|t=0:pdf:None:cyl,i' -v T2
-## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:rainbow:fixc,k:%.2f:0,1:0.,3000.,10:landmask & height:pdf:False:lcc,i' -v LANDMASK,HGT_M
+## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'landmask,height:Time|0:Time|0:XLONG_M:XLAT_M:auto:rainbow,auto,auto:fixc,k:%.2f:0.,1.:0.,3000.,10:landmask & height:pdf:None:lcc,i:True' -v LANDMASK,HGT_M
 ## e.g. # drawing.py -f ~/etudes/domains/MEDCORDEX/geo_em.d01.nc -o draw_2D_shad_cont -S 'height,landmask:Time|0:Time|0:XLONG_M:XLAT_M:terrain:fixc,k:None:0.,3000.:0,1,10:MEDCORDEX height & landmask:pdf:False:lcc,i' -v HGT_M,LANDMASK
 ## e.g. # drawing.py -o draw_2D_shad_line -f 'mean_dtcon-pluc-pres_lat.nc,mean_dtcon-pluc-pres_lat.nc' -S 'dtcon,prc:bottom_top|-1,south_north|-1:latmean:presmean:seismic,k:-5.,5.:monthly|dtcon|&|prc:pdf:flip@y:None:True' -v 'dtconmean,prcmean'
@@ -407,10 +407,25 @@
     draw_2D_shad_cont(ncfile, values, varn)
       ncfile= [ncfilevars],[ncfilevarc] files to use (one value, same file)
-      values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[colorbar]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]
+      values=[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyfmt]:[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]:[close]
         [vnamefs],[vnamefc]: Name in the figure of the shaded and the contour variables
         [dimvals/c]: list of [dimname]|[value] telling at which dimension of the 
           variable a given value is required (no dimension name, all the length)
         [dimx/yvn]: names of the variables with the values of the dimensions for the plot
-        [colorbar]: name of the color bar
+        [dimxyfmt]=[dxf],[Ndx],[dyf],[Ndy]: format of the values at each axis
+          [dxs]: style of x-axis ('auto' for 'pretty')
+            'Nfix', values computed at even 'Ndx'
+            'Vfix', values computed at even 'Ndx' increments
+            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
+          [dxf]: format of the labels at the x-axis
+          [Ndx]: Number of ticks at the x-axis
+          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
+          [dys]: style of y-axis ('auto' for 'pretty')
+          [dyf]: format of the labels at the y-axis
+          [Ndy]: Number of ticks at the y-axis
+          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
+        [colorbarvals]=[colbarn],[fmtcolorbar],[orientation]
+          [colorbarn]: name of the color bar
+          [fmtcolorbar]: format of the numbers in the color bar 'C'-like ('auto' for %6g)
+          [orientation]: orientation of the colorbar ('vertical' (default, by 'auto'), 'horizontal')
         [ckind]: kind of contours 
           'cmap': as it gets from colorbar
@@ -418,5 +433,14 @@
           'fixsigc,[colname]': fixed color [colname], >0 stright, <0 dashed  line
         [clabfmt]: format of the labels in the contour (None, also possible)
-        [smin/axv]: minimum and maximum value for the shading
+        [smin/axv]: minimum and maximum value for the shading or
+          'Srange': for full range
+          'Saroundmean@val': for mean-xtrm,mean+xtrm where xtrm = np.min(mean-min@val,max@val-mean)
+          'Saroundminmax@val': for min*val,max*val
+          'Saroundpercentile@val': for median-xtrm,median+xtrm where xtrm = np.min(median-percentile_(val),
+            percentile_(100-val)-median)
+          'Smean@val': for -xtrm,xtrm where xtrm = np.min(mean-min*@val,max*@val-mean)
+          'Smedian@val': for -xtrm,xtrm where xtrm = np.min(median-min@val,max@val-median)
+          'Spercentile@val': for -xtrm,xtrm where xtrm = np.min(median-percentile_(val),
+             percentile_(100-val)-median)
         [sminc]:[smaxv]:[Nlev]: minimum, maximum and number of values for the contour
         [figt]: title of the figure ('|' for spaces)
@@ -434,4 +458,5 @@
             * 'h', high
             * 'f', full
+        [close]: Whether figure should be finished or not
       valules= 'rh,ta:z|-1,x|-1:z|-1,x|-1:lat:pressure:BuPu:fixsigc,black:%d:0.,100.:195.,305.,7:Meridonal|average|of|rh|&|ta:pdf:flip@y:None'
       varn= [varsn],[varcn] name of the variable to plot with shading variable with contour
@@ -444,7 +469,7 @@
         quit()
 
-    expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[colorbar]:'
-    expectargs = expectargs + '[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],'
-    expectargs = expectargs + '[Nlev]:[figt]:[kindfig]:[reverse]:[mapv]'
+    expectargs = '[vnamefs]:[dimvals]:[dimvalc]:[dimxvn]:[dimyvn]:[dimxyf]:' +       \
+      '[colorbarvals]:[ckind]:[clabfmt]:[sminv],[smaxv]:[sminc],[smaxv],[Nlev]:' +   \
+      '[figt]:[kindfig]:[reverse]:[mapv]:[close]'
  
     drw.check_arguments(fname,values,expectargs,':')
@@ -455,13 +480,15 @@
     vdimxn = values.split(':')[3]
     vdimyn = values.split(':')[4]
-    colbarn = values.split(':')[5]
-    countkind = values.split(':')[6]
-    countlabelfmt = values.split(':')[7]
-    shadminmax = values.split(':')[8]
-    contlevels = values.split(':')[9]
-    figtitle = values.split(':')[10].replace('|',' ')
-    figkind = values.split(':')[11]
-    revals = values.split(':')[12]
-    mapvalue = values.split(':')[13]
+    dimxyf = values.split(':')[5]
+    colorbarvals = values.split(':')[6]
+    countkind = values.split(':')[7]
+    countlabelfmt = values.split(':')[8]
+    shadminmax = values.split(':')[9].split(',')
+    contlevels = values.split(':')[10]
+    figtitle = values.split(':')[11].replace('|',' ')
+    figkind = values.split(':')[12]
+    revals = values.split(':')[13]
+    mapvalue = values.split(':')[14]
+    close = gen.Str_Bool(values.split(':')[15])
 
     if2filenames = ncfile.find(',')
@@ -603,8 +630,8 @@
         countlfmt = countlabelfmt
 
-    shading_nx = np.zeros((2), dtype=np.float)
-    shading_nx[0] = np.float(shadminmax.split(',')[0])
-    shading_nx[1] = np.float(shadminmax.split(',')[1])
-
+    # Shading limits
+    shading_nx = drw.graphic_range(shadminmax,valshad)
+
+    # Contour limits
     clevmin = np.float(contlevels.split(',')[0])
     clevmax = np.float(contlevels.split(',')[1])
@@ -622,9 +649,17 @@
 
     if mapvalue == 'None': mapvalue = None
+
+    colbarn, fmtcolbar, colbaror = drw.colorbar_vals(colorbarvals,',')
+
+    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyf,',')
+    xaxis = [xstyl, xaxf, Nxax, xaxor]
+    yaxis = [ystyl, yaxf, Nyax, yaxor]
+
     if revals == 'None': revals = None
 
     drw.plot_2D_shadow_contour(valshad, valcont, vnamesfig, odimxv, odimyv, odimxu,  \
-      odimyu, dimnamesv, colbarn, countkind, countlfmt, shading_nx, levels_cont,     \
-      varunits, figtitle, figkind, revals, mapvalue)
+      odimyu, xaxis, yaxis, dimnamesv, colbarn, fmtcolbar, colbaror, countkind,      \
+      countlfmt, shading_nx, levels_cont, varunits, figtitle, figkind, revals,       \
+      mapvalue, close)
 
     return
Index: /trunk/tools/drawing_tools.py
===================================================================
--- /trunk/tools/drawing_tools.py	(revision 1146)
+++ /trunk/tools/drawing_tools.py	(revision 1147)
@@ -1850,4 +1850,6 @@
         elif u == 'ms-2': lu='$ms^{-2}$'
         elif u == 'minutes': lu='$minute$'
+        elif u == 'meters MSL': lu='$m$'
+        elif u == 'none': lu='-'
         elif u == 'Pa/s': lu='$Pas^{-1}$'
         elif u == 'Pas-1': lu='$Pas^{-1}$'
@@ -2709,5 +2711,5 @@
     rangegrph = np.zeros((2), dtype=np.float)
 # Changing limits of the colors
-    if type(vrng[0]) != type(np.float(1.)) and type(vrng[0]) != type(np.float64(1.)):
+    if vrng[0][0:1] == 'S':
         if vrng[0] == 'Srange':
             rangegrph[0] = np.min(varsV)
@@ -2765,6 +2767,6 @@
         print '    ' + fname + ': modified shadow min,max:',rangegrph
     else:
-        rangegrph[0] = vrng[0]
-        rangegrph[1] = vrng[1]
+        rangegrph[0] = np.float(vrng[0])
+        rangegrph[1] = np.float(vrng[1])
 
     return rangegrph
@@ -4443,6 +4445,7 @@
     return
 
-def plot_2D_shadow_contour(varsv,varcv,vnames,dimxv,dimyv,dimxu,dimyu,dimn,          \
-  colorbar,ckind,clabfmt,vs,vc,uts,vtit,kfig,reva,mapv):
+def plot_2D_shadow_contour(varsv, varcv, vnames, dimxv, dimyv, dimxu, dimyu, xaxv,   \
+  yaxv, dimn, colorbar, cbarfmt, cbaror, ckind, clabfmt, vs, vc, uts, vtit, kfig,    \
+  reva, mapv, ifclose):
     """ Adding labels and other staff to the graph
       varsv= 2D values to plot with shading
@@ -4451,6 +4454,10 @@
       dim[x/y]v = values at the axes of x and y
       dim[x/y]u = units at the axes of x and y
+      xaxv= list with the x-axis paramteres [style, format, number and orientation]
+      yaxv= list with the y-axis paramteres [style, format, number and orientation]
       dimn= dimension names to plot
       colorbar= name of the color bar to use
+      cbarfmt= format of the numbers in the colorbar
+      cbaror= orientation of the colorbar
       ckind= contour kind
         'cmap': as it gets from colorbar
@@ -4477,4 +4484,5 @@
           * 'h', high
           * 'f', full
+      ifclose= boolean value whether figure should be close (finish) or not
     """
 ##    import matplotlib as mpl
@@ -4488,13 +4496,41 @@
         quit()
 
+    if len(varsv.shape) != 2:
+        print errormsg
+        print '  ' + fname + ': wrong variable shape:',varsv.shape,'is has to be 2D!!'
+        quit(-1)
+    if len(varcv.shape) != 2:
+        print errormsg
+        print '  ' + fname + ': wrong variable contour:',varcv.shape,'is has to be 2D!!'
+        quit(-1)
+
+    # Axis ticks
     # Usually axis > x must be the lon, thus...
     dimxv0 = dimxv.copy()
     dimyv0 = dimyv.copy()
-    dimxt0 = np.array(pretty_int(dimxv.min(),dimxv.max(),10))
-    dimyt0 = np.array(pretty_int(dimyv.min(),dimyv.max(),10))
+
+    dxn = dimxv.min()
+    dxx = dimxv.max()
+    dyn = dimyv.min()
+    dyx = dimyv.max()
+
+    if xaxv[0] == 'pretty':
+        dimxt0 = np.array(pretty_int(dxn,dxx,xaxv[2]))
+    elif xaxv[0] == 'Nfix':
+        dimxt0 = np.arange(dxn,dxx,(dxx-dxn)/(1.*xaxv[2]))
+    elif xaxv[0] == 'Vfix':
+        dimxt0 = np.arange(0,dxx,xaxv[2])
+    if yaxv[0] == 'pretty':
+        dimyt0 = np.array(pretty_int(dyn,dyx,yaxv[2]))
+    elif yaxv[0] == 'Nfix':
+        dimyt0 = np.arange(dyn,dyx,(dyx-dyn)/(1.*yaxv[2]))
+    elif yaxv[0] == 'Vfix':
+        dimyt0 = np.arange(0,dyx,yaxv[2])
+
     dimxl0 = []
-    for i in range(len(dimxt0)): dimxl0.append('{:.1f}'.format(dimxt0[i]))
+    for i in range(len(dimxt0)): dimxl0.append('{:{style}}'.format(dimxt0[i], style=xaxv[1]))
     dimyl0 = []
-    for i in range(len(dimyt0)): dimyl0.append('{:.1f}'.format(dimyt0[i]))
+    for i in range(len(dimyt0)): dimyl0.append('{:{style}}'.format(dimyt0[i], style=yaxv[1]))
+
     dimxT0 = variables_values(dimn[0])[0] + ' (' + units_lunits(dimxu) + ')'
     dimyT0 = variables_values(dimn[1])[0] + ' (' + units_lunits(dimyu) + ')'
@@ -4592,10 +4628,23 @@
 
     else:
-        x,y = gen.lonlat2D(dimxv,dimyv)
+        # No following data values
+        #x = dimxv
+        #y = dimyv
+        x = (dimxv-np.min(dimxv))/(np.max(dimxv) - np.min(dimxv))
+        y = (dimyv-np.min(dimyv))/(np.max(dimyv) - np.min(dimyv))
 
     plt.rc('text', usetex=True)
 
     plt.pcolormesh(x, y, varsv, cmap=plt.get_cmap(colorbar), vmin=vs[0], vmax=vs[1])
-    cbar = plt.colorbar()
+    if cbaror == 'horizontal':
+        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
+        # From: http://stackoverflow.com/questions/32050030/rotation-of-colorbar-tick-labels-in-matplotlib
+        ticklabels= cbar.ax.get_xticklabels()
+        Nticks = len(ticklabels)
+        ticklabs = []
+        for itick in range(Nticks): ticklabs.append(ticklabels[itick].get_text())
+        cbar.ax.set_xticklabels(ticklabs,rotation=90)
+    else:
+        cbar = plt.colorbar(format=cbarfmt,orientation=cbaror)
 
 # contour
@@ -4638,6 +4687,6 @@
         plt.ylabel(dimyT)
 
-        plt.xticks(dimxt, dimxl)
-        plt.yticks(dimyt, dimyl)
+        plt.xticks(dimxt, dimxl, rotation=xaxv[3])
+        plt.yticks(dimyt, dimyl, rotation=yaxv[3])
 
 # set the limits of the plot to the limits of the data
@@ -4646,15 +4695,15 @@
 
 # units labels
-    cbar.set_label(vnames[0].replace('_','\_') + ' (' + units_lunits(uts[0]) + ')')
-    plt.annotate(vnames[1].replace('_','\_') +' (' + units_lunits(uts[1]) + ') [' +  \
+    cbar.set_label(gen.latex_text(vnames[0]) + ' (' + units_lunits(uts[0]) + ')')
+    plt.annotate(gen.latex_text(vnames[1]) +' (' + units_lunits(uts[1]) + ') [' +  \
       mincntS + ', ' + maxcntS + ']', xy=(0.55,0.04), xycoords='figure fraction',    \
       color=coln)
 
     figname = '2Dfields_shadow-contour'
-    graphtit = vtit.replace('_','\_').replace('&','\&')
+    graphtit = gen.latex_text(vtit)
 
     plt.title(graphtit)
     
-    output_kind(kfig, figname, True)
+    output_kind(kfig, figname, ifclose)
 
     return
