Changeset 977 for trunk/UTIL


Ignore:
Timestamp:
Jun 4, 2013, 4:41:53 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. Added rainbow spahetti plot based on an idea by Alizee. Simply set a colormap for a 1D plot and you get it. Also added in pp_reload (simple rainbow function in ppplot). Added also xmin and xmax capabilitiy. Fixed various bugs related to dummy axis, logarithmic axes. Removed time_counter from set_ppclass.txt it is useless in most cases.

Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/les_psfc.py

    r933 r977  
    22from ppclass import pp
    33
    4 les = pp(file="/home/aymeric/Big_Data/psfc_f18.nc",var="PSFC",y=["50,250"],x=["50","100"])
     4les = pp(file="/home/aymeric/Big_Data/LES_dd/psfc_f18.nc",var="PSFC",y=["50,250"],x=["50","100"])
    55les.verbose = True
    66les.getplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/meso_profile.py

    r960 r977  
    1111m.y = -5. # setting a fixed y value
    1212m.z = None # leaving z as a free dimension
    13 m.t = [6.,12.,18.,24.] # setting 4 fixed t values
     13m.t = [6.,9.,12.,15.,18.,21.,24.] # setting 4 fixed t values
    1414
    1515# define settings
     
    1717#m.verbose = True # making the programe verbose
    1818#m.out = "pdf" # output format
     19m.colorb = "spectral" # color cycle according to a color map
    1920
    2021# get data and make plot with default settings
     
    4849S.p[0].xlabel="Potential temperature (K)"
    4950S.filename = "meso_profile"
     51S.colorb = None # come back to default color cycle
    5052
    5153# make the plot
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r972 r977  
    7474parser.add_option('--xcoeff',action='append',dest='xcoeff',type="float",default=None,help="[1D] multiply x axis")
    7575parser.add_option('--ycoeff',action='append',dest='ycoeff',type="float",default=None,help="[1D] multiply y axis")
     76parser.add_option('--xmin',action='append',dest='xmin',type="float",default=None,help="[1D] min bound x axis")
     77parser.add_option('--ymin',action='append',dest='ymin',type="float",default=None,help="[1D] min bound y axis")
     78parser.add_option('--xmax',action='append',dest='xmax',type="float",default=None,help="[1D] max bound x axis")
     79parser.add_option('--ymax',action='append',dest='ymax',type="float",default=None,help="[1D] max bound y axis")
    7680# -- 2D plot
    7781parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png")
  • trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py

    r960 r977  
    77from optparse import OptionParser ### TBR by argparse
    88from ppclass import pp
     9from ppplot import rainbow
    910# -----------------------------------------------------------------------
    1011parser = OptionParser()
     
    3435        plot.proj = opt.proj
    3536    if opt.colorb is not None:
     37      yeah.colorb = opt.colorb
    3638      for plot in yeah.p:
    3739        plot.colorb = opt.colorb
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r972 r977  
    784784                    if self.title is not None: plobj.title = self.title
    785785                    if self.units is not None: plobj.units = self.units
     786                    if self.colorb is not None: plobj.colorb = self.colorb
    786787                    # -- 1D specific
    787788                    if dp == 1:
     
    795796                        if self.vmin is not None: plobj.vmin = self.vmin
    796797                        if self.vmax is not None: plobj.vmax = self.vmax
    797                         if self.colorb is not None: plobj.colorb = self.colorb
    798798                    # finally append plot object
    799799                    self.p.append(plobj)
     
    909909                    self.fig.add_subplot(1,1,1,axisbg=pl.axisbg) # define one subplot (still needed for user-defined font sizes)
    910910                    sav = pl.xlabel,pl.ylabel,pl.xcoeff,pl.ycoeff,pl.title,pl.swaplab # save titles and labels
     911                    # possibility to color lines according to a color map
     912                    # ... made so that all plots span the whole color map automatically.
     913                    if self.colorb is not None:
     914                        if self.verbose: print "**** OK. We make a rainbow spaghetti plot with color map ",self.colorb
     915                        ppplot.rainbow(cb=self.colorb,num=self.howmanyplots)
    911916                else:
    912917                    pl.invert = False ; pl.lstyle = None # don't invert again axis
     
    932937        # once completed show the plot (cannot show intermediate plotin)
    933938        # ... added a fix (customplot=True) for the label problem in basemap
    934         print "**** PPCLASS. Done step: makeplot"
     939        if not self.quiet: print "**** PPCLASS. Done step: makeplot"
    935940        if (self.n == self.howmanyplots):
    936941            ppplot.save(mode=self.out,filename=self.filename,folder=self.folder,custom=self.customplot,includedate=self.includedate,res=self.res)
     
    11331138            except:
    11341139                try: self.p[iii].wscale = opt.wscale[0]
     1140                except: pass
     1141            ###
     1142            try: self.p[iii].xmin = opt.xmin[iii]
     1143            except:
     1144                try: self.p[iii].xmin = opt.xmin[0]
     1145                except: pass
     1146            ###
     1147            try: self.p[iii].ymin = opt.ymin[iii]
     1148            except:
     1149                try: self.p[iii].ymin = opt.ymin[0]
     1150                except: pass
     1151            ###
     1152            try: self.p[iii].xmax = opt.xmax[iii]
     1153            except:
     1154                try: self.p[iii].xmax = opt.xmax[0]
     1155                except: pass
     1156            ###
     1157            try: self.p[iii].ymax = opt.ymax[iii]
     1158            except:
     1159                try: self.p[iii].ymax = opt.ymax[0]
    11351160                except: pass
    11361161
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r972 r977  
    180180# useful functions #
    181181####################
     182
     183# a function to change color lines according to a color map (idea by A. Pottier)
     184# ... two optional arguments: color maps + a number telling how much intervals are needed
     185def rainbow(cb="jet",num=8):
     186    ax = mpl.gca()
     187    pal = mpl.cm.get_cmap(name=cb)
     188    ax._get_lines.set_color_cycle([pal(i) for i in np.linspace(0,0.9,num)])
    182189
    183190# a function to define subplot
     
    299306                 ycoeff=1.,\
    300307                 fmt=None,\
     308                 colorb="jet",\
    301309                 units="",\
    302310                 title=""):
     
    318326        self.fmt = fmt
    319327        self.units = units
     328        self.colorb = colorb
    320329        ## other useful arguments
    321330        ## ... not used here in ppplot but need to be attached to plot object
     
    382391        self.marker = marker
    383392        self.label = label
     393        self.xmin = None
     394        self.ymin = None
     395        self.xmax = None
     396        self.ymax = None
    384397
    385398    # define_from_var
     
    405418        mpl.grid(color='grey')
    406419        if self.lstyle == "": self.lstyle = " " # to allow for no line at all with ""
     420        # set dummy x axis if not defined
     421        if self.absc is None:
     422            self.absc = np.array(range(self.field.shape[0]))
     423            print "!! WARNING !! dummy coordinates on x axis"
    407424        # swapping if requested
    408425        if self.swap:  x = self.field ; y = self.absc
     
    427444        # ... this must be after plot so that axis bounds are well-defined
    428445        # ... also inverting must be after making the thing logarithmic
    429         if self.logx: mpl.semilogx()
    430         if self.logy: mpl.semilogy()
     446        if self.logx: mpl.xscale("log") # not mpl.semilogx() because excludes log on y
     447        if self.logy: mpl.yscale("log") # not mpl.semilogy() because excludes log on x
    431448        if self.invert: ax = mpl.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
    432449        # add a label for line(s)
     
    446463        if xmin < x1: x1 = xmin
    447464        if xmax > x2: x2 = xmax
     465        if self.xmin is not None: x1 = self.xmin
     466        if self.xmax is not None: x2 = self.xmax
    448467        ax.set_xbound(lower=x1,upper=x2)
    449468        # y-axis
     
    453472        if ymin < y1: y1 = ymin
    454473        if ymax > y2: y2 = ymax
     474        if self.ymin is not None: y1 = self.ymin
     475        if self.ymax is not None: y2 = self.ymax
    455476        ax.set_ybound(lower=y1,upper=y2)
    456477        ## set with .div the number of ticks. (is it better than automatic?)
     
    478499                 proj="cyl",\
    479500                 back=None,\
    480                  colorb="jet",\
    481501                 trans=1.0,\
    482502                 addvecx=None,\
     
    498518        self.proj = proj
    499519        self.back = back
    500         self.colorb = colorb
    501520        self.trans = trans
    502521        self.addvecx = addvecx
     
    527546        # get what is done in the parent class...
    528547        plot.make(self)
    529         if self.fmt is None: self.fmt = "%.2e"
     548        if self.fmt is None: self.fmt = "%.1e"
    530549        # ... then add specific stuff
    531550        ############################################################################################
    532551        ### PRE-SETTINGS
    533552        ############################################################################################
    534         # transposing if necessary
    535         shape = self.field.shape
    536         if shape[0] != shape[1]:
    537          if len(self.absc) == shape[0] and len(self.ordi) == shape[1]:
    538             print "!! WARNING !! Transposing axes"
    539             self.field = np.transpose(self.field)
    540553        # set dummy xy axis if not defined
    541554        if self.absc is None:
     
    547560            self.mapmode = False
    548561            print "!! WARNING !! dummy coordinates on y axis"
     562        # transposing if necessary
     563        shape = self.field.shape
     564        if shape[0] != shape[1]:
     565         if len(self.absc) == shape[0] and len(self.ordi) == shape[1]:
     566            print "!! WARNING !! Transposing axes"
     567            self.field = np.transpose(self.field)
    549568        # bound field
    550569        zevmin, zevmax = calculate_bounds(self.field,vmin=self.vmin,vmax=self.vmax)
  • trunk/UTIL/PYTHON/planetoplot_v2/set_ppclass.txt

    r936 r977  
    1313  # t-axis: possible names to search for. add in the line with a separating ;
    1414  #
    15 Times;time;Time;time_counter;Ls
     15Times;time;Time;Ls
    1616  # area: possible names to search for. add in the line with a separating ;
    1717  #
Note: See TracChangeset for help on using the changeset viewer.