Changeset 1545 in lmdz_wrf for trunk


Ignore:
Timestamp:
Apr 27, 2017, 1:25:16 AM (8 years ago)
Author:
lfita
Message:

Adding `draw_bar_line': Function to plot a bar char and line figure with multiple sources
Fixing some issues in plot_bar', plot_bar_time'

Location:
trunk/tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/documentation/plotting/gallery.html

    r1542 r1545  
    1919      <A HREF="2Dshad_line_time.html"><IMG SRC="figs/hus-ps_vert-sec_shad-line_time.png" ALT="2D shadow line time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2020      <A HREF="draw_bar.html"><IMG SRC="figs/bar_rain_CRU-NCEP_norm.png" ALT="bar char plot" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
     21      <A HREF="bar_line.html"><IMG SRC="figs/bar-line_rain_CRU-NCEP_norm.png" ALT="bar char and lines plot" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2122      <A HREF="bar_time.html"><IMG SRC="figs/bar_time_rain_CRU-NCEP_DJFmean_norm.png" ALT="bar char plot time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
    2223      <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_wss.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
  • trunk/tools/documentation/plotting/plotting.html

    r1542 r1545  
    1515      <A CLASS="lc" HREF="2Dshad_line_time.html" TARGET="value">2D shadow line time</A><BR>
    1616      <A CLASS="lc" HREF="draw_bar.html" TARGET="value">bar</A><BR>
     17      <A CLASS="lc" HREF="bar_line.html" TARGET="value">bar & line</A><BR>
    1718      <A CLASS="lc" HREF="bar_time.html" TARGET="value">bar_time</A><BR>
    1819      <A CLASS="lc" HREF="barbs.html" TARGET="value">barbs</A><BR>
  • trunk/tools/drawing.py

    r1542 r1545  
    4747## e.g. # drawing.py -o draw_bar -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm' -S 'Stringlist,%s,January@Feburary@March@Arpil@May@June@July@August@September@October@November@December,25,pretty,auto,auto,auto:time!since!1958-01-01:pr:y:seconds:mmd-1:SESA,SACZ:#AA0000,#0000AA:1000000.:normalized!evolution!of!precipitaion!with!CRU-NCEP!forcing:0|10:png:bar_rain_CRU-NCEP_norm:yes'
    4848## e.g. # drawing.py -o draw_bar_time -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm' -S 'auto;pr;1;y;None;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ;#AA0000,#0000AA;10000000.;normalized!evolution!of!DJFmean!of!precipitaion!with!CRU-NCEP!forcing;0|10;png;bar_time_rain_CRU-NCEP_DJFmean_norm;yes'
    49 
     49## e.g. # drawing.py -o draw_bar_line -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm;bar:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,12@24@1;time_counter;rainnorm;bar:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm;line:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,12@24@1;time_counter;rainnorm;line' -S 'Stringlist,%s,January@Feburary@March@April@May@June@July@August@September@October@November@December@Jan@Feb@Mar@Apr@May@Jun@Jul@Aug@Sept@Oct@Nov@Dec,25,pretty,auto,auto,auto:time!since!1958-01-01:pr:x:-4.,4.:seconds:1:$SESA_{1958}$,$SESA_{1959}$,$SACZ_{1958}$,$SACZ_{1959}$:#AA0000,#0000AA:1000000.:#00AA00,#AAAA00:-.:,:2.:2.:all:normalized!evolution!of!precipitation!with!CRU-NCEP!forcing:0|10:png:bar-line_rain_CRU-NCEP_norm:yes'
    5050
    5151
     
    8383# draw_2lines_time: Function to plot two time-lines in different axes (x/x2 or y/y2)
    8484# draw_bar: Function to plot a bar char figure with multiple sources
     85# draw_bar_line: Function to plot a bar char and line figure with multiple sources
    8586# draw_bar_time: Function to plot a bar char figure with multiple sources and time axis
    8687# draw_barbs: Function to plot wind barbs
     
    115116  'draw_2D_shad_cont', 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time',               \
    116117  'draw_2D_shad_line',                                                               \
    117   'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_time', 'draw_barbs',               \
    118    'draw_basins',                                                                    \
     118  'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_line', 'draw_bar_time',            \
     119  'draw_barbs', 'draw_basins',                                                       \
    119120  'draw_2lines', 'draw_2lines_time', 'draw_lines', 'draw_lines_time',                \
    120121  'draw_Neighbourghood_evol',                                                        \
     
    64706471        [yunits]: units of the y-label
    64716472        [aval]: which acis should be used for the values ('x' or 'y')
    6472         [labels]: ',' list of labels for the legend ('None' for no-labels)
     6473        [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces)
    64736474        [colors]: ',' list of colors (single value same color, 'auto' automatic)
    64746475        [wdth]: width of the bars
     
    65016502    xunits = values.split(':')[4]
    65026503    yunits = values.split(':')[5]
    6503     labels = gen.str_list(values.split(':')[6], ',')
     6504    labels = gen.str_list(values.split(':')[6].replace('!', ' '), ',')
    65046505    colors = gen.str_list(values.split(':')[7], ',')
    65056506    wdth = np.float(values.split(':')[8])
     
    66276628               'l': milisecond
    66286629          [tfmt]; desired format
    6629         [labels]: ',' list of labels for the legend ('None' for no-labels)
     6630        [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces)
    66306631        [colors]: ',' list of colors (single value same color, 'auto' automatic)
    66316632        [wdth]: width of the bars
     
    66586659    rangevals = values.split(';')[4]
    66596660    timevals = values.split(';')[5]
    6660     labels = gen.str_list(values.split(';')[6], ',')
     6661    labels = gen.str_list(values.split(';')[6].replace('!', ' '), ',')
    66616662    colors = gen.str_list(values.split(';')[7], ',')
    66626663    wdth = np.float(values.split(';')[8])
     
    67696770        valmin = np.float(rangevals.split(',')[0])
    67706771        valmax = np.float(rangevals.split(',')[1])
    6771         if valmin != 'auto': valmin = np.min(yvals)
    6772         if valmax != 'auto': valmax = np.max(yvals)
     6772        if valmin == 'auto': valmin = np.min(yvals)
     6773        if valmax == 'auto': valmax = np.max(yvals)
    67736774    yrange = [valmin, valmax]
    67746775
     
    67846785    drw.plot_bars_time(tvals, yvals, timepos, timelabels, yaxis, dyu, aval, yrange,  \
    67856786     timen, yaxislab, labels, colors, wdth, graphtit, legloc, legsiz, kindfig, fign, \
     6787     close)
     6788
     6789    return
     6790
     6791def draw_bar_line(ncfile, values):
     6792    """ Function to plot a bar char and lines plot figure with multiple sources
     6793      ncfile = ':' list of [filen];[dimslice];[xvarn];[yvarn];[kind]
     6794        [filen]: name of the file
     6795        [dimslice]: '|' list of [dimn],[dimrange]
     6796          [dimn]: name of the dimension
     6797          [dimrange]: range for the slice
     6798            * [integer]: which value of the dimension
     6799            * -1: all along the dimension
     6800            * -9: last value of the dimension
     6801            * [beg]@[end]@[inc] slice from [beg] to [end] every [inc]
     6802            * NOTE, no dim name all the dimension size
     6803        [xvarn]: name of the variable to use for the x-positions
     6804        [yvarn]: name of the variable to use for the values
     6805        [kind]: Kind of plotting
     6806          'bar': for bar-plot
     6807          'line': for line-plot
     6808      values = [dimxyfmt]:[xaxislab]:[yaxislab]:[xunits]:[yunits]:[aval]:[rangevals]:[labels]:
     6809          [colors]:[wdth]:[colns]:[lines]:[points]:[lwdths]:[psizes]:[freqv]:[graphtit]:[legvalues]:
     6810          [kindfig]:[fign]:[close]
     6811        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordy]: format of the values at each
     6812            axis (or single 'auto' for 'auto','auto')
     6813          [dxs]: style of x-axis ('auto' for 'pretty')
     6814            'Nfix', values computed at even 'Ndx'
     6815            'Stringlist', a given list of strings
     6816            'Vfix', values computed at even 'Ndx' increments
     6817            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
     6818          [dxf]: format of the labels at the x-axis
     6819          [Ndx]: Number of ticks at the x-axis (for 'Stringlist', '@' list of labels)
     6820          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
     6821          [dys]: style of y-axis ('auto' for 'pretty')
     6822          [dyf]: format of the labels at the y-axis
     6823          [Ndy]: Number of ticks at the y-axis
     6824          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
     6825        [xaxislab]: Label for the x-axis ('!' for spaces)
     6826        [yaxislab]: Label for the y-axis ('!' for spaces)
     6827        [xunits]: units of the x-label ('None' for no units)
     6828        [yunits]: units of the y-label
     6829        [aval]: which acis should be used for the values ('x' or 'y')
     6830        [rangevals]: Range of the axis with the values (singel 'None' for 'auto','auto')
     6831         [vmin],[vmax]: minimum and maximum values
     6832           'auto': the computed minimumm or maximum of the values 
     6833        [labels]: ',' list of labels for the legend ('None' for no-labels, '!' for spaces)
     6834        [colors]: ',' list of colors (single value same color, 'auto' automatic)
     6835        [wdth]: width of the bars
     6836        [colns]= ',' list of color names ('None' for automatic, single value for all the same)
     6837        [lines]= ',' list of style of lines ('None' for automatic, single value for all the same)
     6838        [points]= '@' list of style of points ('None' for automatic, single value for all the same)
     6839        [lwdths]= ',' list of withs of lines ('None' for automatic, single value for all the same)
     6840        [psizes]= ',' list of size of points ('None' for automatic, single value for all the same)
     6841        [freqv]= frequency of values ('all' for all values)
     6842        [graphtit]: title of the figure '!' for spaces
     6843        [legvalues]=[locleg]|[fontsize]:
     6844          [locleg]: location of the legend (0, autmoatic)
     6845            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     6846            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     6847            9: 'upper center', 10: 'center'
     6848          [fontsize]: font size for the legend (auto for 12)
     6849        [kindfig]: kind of output figure (png, pdf, ps)
     6850        [fign]: name of the figure (without extension)
     6851        [close]: whether figure should be close or not
     6852    """
     6853    fname = 'draw_bar_line'
     6854
     6855    if values == 'h':
     6856        print fname + '____________________________________________________________'
     6857        print draw_bar_line.__doc__
     6858        quit()
     6859
     6860    expectargs = '[dimxyfmt]:[xaxislab]:[yaxislab]:[aval]:[rangevals]:[xunits]:' +   \
     6861      '[yunits]:[labels]:[colors]:[wdth]:[colns]:[lines]:[points]:[lwdths]:' +       \
     6862      '[psizes]:[freqv]:[graphtit]:[legvalues]:[kindfig]:[fign]:' + \
     6863      '[close]'
     6864    drw.check_arguments(fname,values,expectargs,':')
     6865
     6866    dimxyfmt = values.split(':')[0]
     6867    xaxislab = values.split(':')[1].replace('!',' ')
     6868    yaxislab = values.split(':')[2].replace('!',' ')
     6869    aval = values.split(':')[3]
     6870    rangevals = values.split(':')[4]
     6871    xunits = values.split(':')[5]
     6872    yunits = values.split(':')[6]
     6873    labels = gen.str_list(values.split(':')[7].replace('!', ' '), ',')
     6874    colors = gen.str_list(values.split(':')[8], ',')
     6875    wdth = np.float(values.split(':')[9])
     6876    colns = gen.str_list(values.split(':')[10], ',')
     6877    lines = gen.str_list(values.split(':')[11], ',')
     6878    points = gen.str_list(values.split(':')[12], '@')
     6879    lwdths = gen.str_list_k(values.split(':')[13], ',', 'R')
     6880    psizes = gen.str_list_k(values.split(':')[14], ',', 'R')
     6881    freqv0 = values.split(':')[15]
     6882    graphtit = values.split(':')[16].replace('!',' ')
     6883    legvalues = values.split(':')[17]
     6884    kindfig = values.split(':')[18]
     6885    fign = values.split(':')[19]
     6886    close = gen.Str_Bool(values.split(':')[20])
     6887
     6888    # files and values
     6889    filedvs = ncfile.split(':')
     6890    barxvals = []
     6891    baryvals = []
     6892    linexvals = []
     6893    lineyvals = []
     6894    namebars = []
     6895    namelines = []
     6896
     6897    valmin = gen.fillValueF
     6898    valmax = -gen.fillValueF
     6899    print '  ' + fname + 'plotting _______'
     6900    il = 0
     6901    for fdv in filedvs:
     6902        filen = fdv.split(';')[0]
     6903        dimrange = fdv.split(';')[1]
     6904        xvarn = fdv.split(';')[2]
     6905        yvarn = fdv.split(';')[3]
     6906        plotk = fdv.split(';')[4]
     6907        print '  ', filen, 'with', plotk
     6908
     6909        if not os.path.isfile(filen):
     6910            print errormsg
     6911            print '  ' + fname + ': file "' + filen + '" does not exist !!'
     6912            quit(-1)
     6913
     6914        onc = NetCDFFile(filen, 'r')
     6915        if not onc.variables.has_key(xvarn):
     6916            print errormsg
     6917            print '  ' + fname + ': file "' + filen + "' does not have variable '" + \
     6918              xvarn + "' for the x-values !!"
     6919            print '    available ones:', onc.variables.keys()
     6920            onc.close()
     6921            quit(-1)
     6922        if not onc.variables.has_key(yvarn):
     6923            print errormsg
     6924            print '  ' + fname + ': file "' + filen + "' does not have variable '" + \
     6925              yvarn + "' for the y-values !!"
     6926            print '    available ones:', onc.variables.keys()
     6927            onc.close()
     6928            quit(-1)
     6929
     6930        oxvar = onc.variables[xvarn]
     6931        oyvar = onc.variables[yvarn]
     6932        xvs, xdims = ncvar.slice_variable(oxvar, dimrange.replace(',',':'))
     6933        yvs, ydims = ncvar.slice_variable(oyvar, dimrange.replace(',',':'))
     6934        if len(xvs.shape) != 1:
     6935            print errormsg
     6936            print '  ' + fname + ': provided slice:', dimrange, "for variable '" +   \
     6937              xvarn + "' does not provide a rank-1 value !!"
     6938            print '    resultant shape:', xvs.shape, 'dimensions:', xdims, 'fix it!!'
     6939            quit(-1)
     6940        if len(yvs.shape) != 1:
     6941            print errormsg
     6942            print '  ' + fname + ': provided slice:', dimrange, "for variable '" +   \
     6943              yvarn + "' does not provide a rank-1 value !!"
     6944            print '    resultant shape:', yvs.shape, 'dimensions:', ydims, 'fix it!!'
     6945            quit(-1)
     6946
     6947        # Location of each kind
     6948        if plotk == 'bar':
     6949            barxvals.append(list(xvs))
     6950            baryvals.append(list(yvs))
     6951            if labels is not None: namebars.append(labels[il])
     6952        elif plotk == 'line':
     6953            linexvals.append(list(xvs))
     6954            lineyvals.append(list(yvs))
     6955            if labels is not None: namelines.append(labels[il])
     6956        else:
     6957            print errormsg
     6958            print '  ' + fname + ": kind of input '" + plotk + "' not ready!!"
     6959            print '    available ones:', ['bar', 'line']
     6960            quit(-1)
     6961
     6962        yvsn = np.min(yvs)
     6963        yvsx = np.max(yvs)
     6964        if yvsn < valmin: valmin = yvsn
     6965        if yvsx > valmax: valmax = yvsx
     6966
     6967        onc.close()
     6968        il = il + 1
     6969
     6970    # ranges
     6971    if rangevals == 'None':
     6972        valmin = yvsn
     6973        valmax = yvsx
     6974    else:
     6975        valmin = np.float(rangevals.split(',')[0])
     6976        valmax = np.float(rangevals.split(',')[1])
     6977        if valmin == 'auto': valmin = yvsn
     6978        if valmax == 'auto': valmax = yvsx
     6979    yrange = [valmin, valmax]
     6980
     6981    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
     6982    xaxis = [xstyl, xaxf, Nxax, xaxor]
     6983    yaxis = [ystyl, yaxf, Nyax, yaxor]
     6984
     6985    # Frequqnecy for lines
     6986    if freqv0 == 'all':
     6987        freqv = None
     6988    else:
     6989        freqv = int(freqv0)
     6990
     6991    # Legend
     6992    legloc, legsiz = drw.legend_values(legvalues,'|')
     6993
     6994    # units
     6995    if xunits == 'None': dxu = None
     6996    else: dxu = xunits
     6997    dyu = yunits
     6998
     6999    drw.plot_bars_line(barxvals, baryvals, linexvals, lineyvals, xaxis, yaxis, dxu,  \
     7000     dyu, aval, yrange, xaxislab, yaxislab, namebars, namelines, colors, wdth, colns,\
     7001     lines, points, lwdths, psizes, freqv, graphtit, legloc, legsiz, kindfig, fign,  \
    67867002     close)
    67877003
     
    68107026  'draw_2D_shad_cont_time',                                                          \
    68117027  'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time',  \
    6812   'draw_bar', 'draw_bar_time', 'draw_lines',                                         \
     7028  'draw_bar', 'draw_bar_line', 'draw_bar_time', 'draw_lines',                        \
    68137029  'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_topo_geogrid_boxes',        \
    68147030  'draw_trajectories', 'draw_vals_trajectories', 'variable_values']
     
    68687084    elif oper == 'draw_bar':
    68697085        draw_bar(opts.ncfile, opts.values)
     7086    elif oper == 'draw_bar_line':
     7087        draw_bar_line(opts.ncfile, opts.values)
    68707088    elif oper == 'draw_bar_time':
    68717089        draw_bar_time(opts.ncfile, opts.values)
  • trunk/tools/drawing_tools.py

    r1544 r1545  
    8585# plot_2lines_time: Function to plot two time-lines in different axes (x/x2 or y/y2)
    8686# plot_bars: Function to plot a bar plot with multiple columns
     87# plot_bars_line: Function to plot a bar and lines plot with multiple columns
     88# plot_bars_time: Function to plot a bar plot with multiple columns with time axis
    8789# plot_lines: Function to plot a collection of lines
    8890# plot_Taylor: Function to draw a Taylor diagram (Taylor 2001)
     
    91709172        if len(NOTcoinc) != 0:
    91719173            xticks = xticks + NOTcoinc
    9172             xticks.sort
     9174            xticks.sort()
    91739175
    91749176    dxn = np.min(xvalues)
     
    92649266            if labels is not None:
    92659267                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv],     \
    9266                   label=labels[iv])
     9268                  label=gen.latex_text(labels[iv]))
    92679269            else:
    92689270                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv])
     
    92709272            if labels is not None:
    92719273                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv],       \
    9272                   label=labels[iv])
     9274                  label=gen.latex_text(labels[iv]))
    92739275            else:
    92749276                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv])
     
    93949396            if labels is not None:
    93959397                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv],     \
    9396                   label=labels[iv])
     9398                  label=gen.latex_text(labels[iv]))
    93979399            else:
    93989400                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv])
     
    94009402            if labels is not None:
    94019403                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv],       \
    9402                   label=labels[iv])
     9404                  label=gen.latex_text(labels[iv]))
    94039405            else:
    94049406                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv])
     
    94279429
    94289430
     9431def plot_bars_line(bxvalues, byvalues, lxvalues, lyvalues, xaxv, yaxv, dimxu, dimyu, \
     9432  valaxis, valrange, xlabel, ylabel, blabels, llabels, bcols, width, coll, typl, ptl,\
     9433   wdtl, ptz, ptf, gtit, lloc, lsiz, kfig, figname, ifclose):
     9434    """ Function to plot a bar and lines plot with multiple columns
     9435      bxvalues= list with the values along the x-ais for bar plot
     9436      byvalues= list with the values along the y-ais for bar plot
     9437      lxvalues= list with the values along the x-ais for lines plot
     9438      lyvalues= list with the values along the y-ais for lines plot
     9439      [x/y]axv= values at the axes of x and y
     9440      dim[x/y]u= units at the axes of x and y
     9441      valaxis= which axis holds the values 'x' or 'y'
     9442      valrange= range of values along the values axis
     9443      xlabel= label at the x-axis
     9444      ylabel= label at the y-axis
     9445      blabels= list of labels for legend (None for no legend) for bars
     9446      llabels= list of labels for legend (None for no legend) for lines
     9447      bcols= list of colors for the bars (single value for the same, 'auto' for automatic)
     9448      width= size of the column
     9449      coll= ',' list of colors for the lines, 'None' for automatic, single
     9450        value all the same
     9451      typl= ',' list of type for the lines, 'None' for automatic, single
     9452        value all the same
     9453      ptl= ',' list of type of points for the lines, 'None' for automatic, single
     9454        value all the same
     9455      wdtl= ',' list of width for the lines, 'None' for automatic, single
     9456        value all the same
     9457      ptz= ',' list of size of points for the lines, 'None' for automatic, single
     9458        value all the same
     9459      ptf= frequency of point plotting, 'all' for all time steps
     9460      gtit= title of the figure
     9461      lloc= location of the legend (0, autmoatic)
     9462        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
     9463        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
     9464        9: 'upper center', 10: 'center'
     9465      lsiz= font size of the legend
     9466      kfig= kind of output: pdf, png, ps
     9467      figname= name of the figure
     9468      ifclose= whether figure should be closed
     9469    """
     9470    fname = 'plot_bars_line'
     9471
     9472    bNvalues = len(bxvalues)
     9473    lNvalues = len(lxvalues)
     9474
     9475    if lNvalues > 0:
     9476        # Lines' characteristics
     9477        cols, lins, pts, lws, pss = ColorsLinesPointsStyles(lNvalues, coll, typl,    \
     9478          ptl, wdtl, ptz, ptf)
     9479
     9480    # Maximum number of values:
     9481    Lmaxvals = -10
     9482    if bNvalues > 0:
     9483        xticks = bxvalues[0]
     9484        for iv in range(bNvalues):
     9485            if len(bxvalues[iv]) > Lmaxvals: Lmaxvals = len(bxvalues[iv])
     9486            NOTcoinc = list(set(bxvalues[iv]).difference(set(xticks)))
     9487            if len(NOTcoinc) != 0:
     9488                xticks = xticks + NOTcoinc
     9489                xticks.sort()
     9490    if lNvalues > 0:
     9491        if bNvalues == 0: xticks = lxvalues[0]
     9492        for iv in range(lNvalues):
     9493            if len(lxvalues[iv]) > Lmaxvals: Lmaxvals = len(lxvalues[iv])
     9494            NOTcoinc = list(set(lxvalues[iv]).difference(set(xticks)))
     9495            if len(NOTcoinc) != 0:
     9496                xticks = xticks + NOTcoinc
     9497                xticks.sort()
     9498
     9499    dxn = np.min([bxvalues, lxvalues])
     9500    dxx = np.max([bxvalues, lxvalues])
     9501    dyn = valrange[0]
     9502    dyx = valrange[1]
     9503
     9504    axstyles = ['pretty', 'Nfix', 'Stringlist', 'Vfix']
     9505    if xaxv[0] == 'pretty':
     9506        dimxt = np.array(gen.pretty_int(dxn,dxx,xaxv[2]))
     9507        dimxl = np.array(dimxt, dtype=str)
     9508    elif xaxv[0] == 'Nfix':
     9509        dimxl = np.arange(0.,1.,1./(xaxv[2]+1))
     9510        dimxt = np.arange(0.,1.,1./varsv.shape[1])
     9511    elif xaxv[0] == 'Stringlist':
     9512        if len(xaxv[2]) != len(xticks):
     9513            print warnmsg
     9514            print '  ' + fname + ': number of ticks to plot=', len(xticks),         \
     9515              'and number of labels provided', len(xaxv[2]), 'differ !!'
     9516            print '  ' + fname + ': ticks to plot=', xticks, 'and provided labels', \
     9517                xaxv[2], 'differ !!'
     9518
     9519        dimxl = xaxv[2]
     9520        dimxt = xticks
     9521    elif xaxv[0] == 'Vfix':
     9522        dxnvfix = int(dxn/xaxv[2])
     9523        dimxt = np.arange(dxnvfix*xaxv[2],dxx,xaxv[2])
     9524    else:
     9525        print errormsg
     9526        print '  ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!"
     9527        print '    available ones: ', axstyles
     9528        quit(-1)
     9529
     9530    if yaxv[0] == 'pretty':
     9531        dimyt = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
     9532        dimyl = np.array(dimyt, dtype=str)
     9533    elif yaxv[0] == 'Nfix':
     9534        dimyt = np.arange(0.,1.,1./(yaxv[2]+1))
     9535        dimyl = np.arange(0.,1.,1./varsv.shape[0])
     9536        axytype='fixpixel'
     9537    elif yaxv[0] == 'Vfix':
     9538        dynvfix = int(dyn/yaxv[2])
     9539        dimyt = np.arange(dynvfix*xaxv[2],dyx,yaxv[2])
     9540        axytype='data'
     9541    else:
     9542        print errormsg
     9543        print '  ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!"
     9544        print '    available ones: ', axstyles
     9545        quit(-1)
     9546
     9547    if valaxis == 'x':
     9548        orient = 'horizontal'
     9549    else:
     9550        orient = 'vertical'
     9551
     9552    bcolvs = []
     9553    if len(bcols) == 1:
     9554        if cols[0] == 'auto':
     9555            bcolvs = colorsauto[0:bNvalues+1]
     9556        else:
     9557            for ic in range(bNvalues): bcolvs.append(bcols[0])
     9558    else:
     9559        bcolvs = bcols
     9560   
     9561    if bNvalues > 0:
     9562        for iv in range(bNvalues):
     9563            xvls = bxvalues[iv]
     9564            Lvalues = len(xvls)
     9565            dxmean = np.mean(np.array(xvls[1:Lvalues])-np.array(xvls[0:Lvalues-1]))
     9566            if dxmean < width*bNvalues:
     9567                print warnmsg
     9568                print '  ' + fname + ': mean distance among x-values:', dxmean,      \
     9569                  'is smaller than the total number of bars with the given witdh (', \
     9570                  width, '):', width*bNvalues
     9571                print '    reduce widht of the column, should not be larger than:',  \
     9572                  dxmean/bNvalues
     9573            if width*bNvalues < 0.01*dxmean:
     9574                print warnmsg
     9575                print '  ' + fname + ': mean distance among x-values:', dxmean,      \
     9576                  'is 100-times larger than the total number of bars with the given'+\
     9577                  ' witdh (', width, '):', width*bNvalues
     9578                print '    increase widht of the column, should not be smaller ' +   \
     9579                  'than:', 0.01*dxmean
     9580
     9581            # Relative position of the column respect the xtick
     9582            if np.mod(bNvalues,2) == 0:
     9583                xrel = width*(iv - bNvalues/2.)
     9584            else:
     9585                xrel = width*(iv - (bNvalues-1)/2.)
     9586
     9587            xrels = xrel*np.ones((Lvalues),dtype=np.float)
     9588
     9589            if valaxis == 'x':
     9590                if blabels is not None:
     9591                    plt.barh(xvls+xrels, byvalues[iv], height=width,color=bcolvs[iv],\
     9592                      label=gen.latex_text(blabels[iv]))
     9593                else:
     9594                    plt.barh(xvls+xrels, byvalues[iv], height=width, color=bcolvs[iv])
     9595            else:
     9596                if blabels is not None:
     9597                    plt.bar(xvls+xrels, byvalues[iv], width=width, color=bcolvs[iv], \
     9598                      label=gen.latex_text(blabels[iv]))
     9599                else:
     9600                    plt.bar(xvls+xrels, byvalues[iv], width=width, color=bcolvs[iv])
     9601 
     9602    if lNvalues > 0:
     9603        for iv in range(lNvalues):
     9604            if valaxis == 'x':
     9605                if llabels is not None:
     9606                    plt.plot(lyvalues[iv], lxvalues[iv], lins[iv], marker=pts[iv],   \
     9607                      color=cols[iv], label=gen.latex_text(llabels[iv]),             \
     9608                      linewidth=lws[iv], markersize=pss[iv], markevery=ptf)
     9609                else:
     9610                    plt.plot(lyvalues[iv], lxvalues[iv], lins[iv], marker=pts[iv],   \
     9611                      color=cols[iv],linewidth=lws[iv], markersize=pss[iv],          \
     9612                      markevery=ptf)
     9613            else:
     9614                if llabels is not None:
     9615                    plt.plot(lxvalues[iv], lyvalues[iv], lins[iv], marker=pts[iv],   \
     9616                      color=cols[iv], label=gen.latex_text(vlabels[iv]),             \
     9617                      linewidth=lws[iv], markersize=pss[iv], markevery=ptf)
     9618                else:
     9619                    plt.plot(lxvalues[iv], lyvalues[iv], lins[iv], marker=pts[iv],   \
     9620                      color=cols[iv],linewidth=lws[iv], markersize=pss[iv],          \
     9621                      markevery=ptf)
     9622
     9623    if valaxis == 'x':
     9624        plt.xticks(dimyt, dimyl, rotation=yaxv[3])
     9625        plt.yticks(dimxt, list(dimxl), rotation=xaxv[3])
     9626        plt.xlabel(ylabel + ' (' + units_lunits(dimyu) + ')')
     9627        if dimxu is not None:
     9628            plt.ylabel(xlabel + ' (' + units_lunits(dimxu) + ')')
     9629        else:
     9630            plt.ylabel(xlabel)
     9631        plt.xlim(dyn, dyx)
     9632    else:
     9633        plt.xticks(dimxt, list(dimxl), rotation=xaxv[3])
     9634        plt.yticks(dimyt, list(dimyl), rotation=yaxv[3])
     9635        if dimxu is not None:
     9636            plt.xlabel(xlabel + ' (' + units_lunits(dimxu) + ')')
     9637        else:
     9638            plt.xlabel(xlabel)
     9639        plt.ylabel(ylabel + ' (' + units_lunits(dimyu) + ')')
     9640        plt.ylim(dyn, dyx)
     9641
     9642    if blabels is not None or llabels is not None:
     9643        plt.legend(loc=lloc, prop={'size':lsiz})
     9644
     9645    plt.title(gen.latex_text(gtit))
     9646   
     9647    output_kind(kfig, figname, ifclose)
     9648
     9649    return
     9650
     9651
Note: See TracChangeset for help on using the changeset viewer.