Ignore:
Timestamp:
Dec 8, 2011, 1:12:21 AM (13 years ago)
Author:
aslmd
Message:

UTIL: PYTHON: spaghetti plot is default for 1D plots. handling 1D plot can be quite improved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot.py

    r457 r458  
    7272    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    7373    import matplotlib as mpl
    74     from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close
     74    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend
    7575    from matplotlib.cm import get_cmap
    7676    import numpy as np
     
    154154          vert = nc.variables["altitude"][:]
    155155      elif typefile in ['meso','mesoapi','geo','mesoideal']:
     156          ### the following lines are kind of dirty... not possible to ask for several lats and lons
    156157          if vlon is not None or vlat is not None:   indices = bidimfind(lon2d,lat2d,vlon,vlat) ; print '********** INDICES: ', indices
    157158          if slon is not None: slon[0][0] = indices[0] ; slon[0][1] = indices[0]
     
    254255    print "********************************************"
    255256    while error is False:
    256        print "********** NPLOT", nplot
    257      
    258        ### General plot settings
     257     
     258       print "********** NPLOT", nplot
    259259       if nplot > numplot: break
    260        if numplot > 1:  subplot(subv,subh,nplot)
    261 
    262        ### Map projection                   
    263        if mapmode == 1:     m = define_proj(proj,wlon,wlat,back=back,blat=blat,blon=blon) ; x, y = m(lon2d, lat2d)
    264        elif mapmode ==0:    m = None ; x = None ; y = None
    265260
    266261       ####################################################################
     
    301296           vecy, error = reducefield( all_windv[index_f], d4=indextime, d3=indexvert, yint=yintegral, alt=vert)
    302297       ####################################################################
     298       ### General plot settings
     299       changesubplot = (numplot > 1) and (len(what_I_plot.shape) != 1)  ## default for 1D plots: superimposed. to be reworked for better flexibility.
     300       if changesubplot: subplot(subv,subh,nplot)
     301       ### Map projection                   
     302       if mapmode == 1:     m = define_proj(proj,wlon,wlat,back=back,blat=blat,blon=blon) ; x, y = m(lon2d, lat2d)
     303       elif mapmode ==0:    m = None ; x = None ; y = None
     304       ####################################################################
    303305
    304306       if not error:
     
    371373                            elif mapmode == 0:     contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans)
    372374                        else:
    373                             if mapmode == 1:       m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax ,alpha=trans)
    374                             elif mapmode == 0:     pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax ,alpha=trans)
     375                            if mapmode == 1:       m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax, alpha=trans)
     376                            elif mapmode == 0:     pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax, alpha=trans)
    375377                        if colorb != 'nobar':       
    376378                            if (fileref is not None) and (index_f is numplot-1):   daformat = "%.3f"
     
    432434               ##### 1D field
    433435               elif len(what_I_plot.shape) is 1:
    434                  plot(x,what_I_plot)
     436                 lbl = ""
     437                 if indexlat is not None:  lbl = lbl + " ix" + str(indexlat)
     438                 if indexlon is not None:  lbl = lbl + " iy" + str(indexlon)
     439                 if indexvert is not None: lbl = lbl + " iz" + str(indexvert)
     440                 if indextime is not None: lbl = lbl + " it" + str(indextime)
     441
     442                 if indexvert is not None:    plot(x,what_I_plot,label=lbl)  ## regular plot
     443                 else:                        plot(what_I_plot,x,label=lbl)  ## vertical profile
     444                 legend(loc='best')
    435445                 if save == 'txt':  writeascii(np.transpose(what_I_plot),'profile'+str(nplot)+'.txt')
    436446
Note: See TracChangeset for help on using the changeset viewer.