Exemplo n.º 1
0
def plot(x, \
        y1, y2 = [] , y3 = [], lbl_y1 = '', lbl_y2 = '', lbl_y3 = ''
        ,plot_exportPET_fn = '', MMsurf_plot = 0, strTitle = 'Title'):

##    if len(x)>35:
##        locX = mpl.dates.MonthLocator()
##    else:
##        locX = mpl.dates.HourLocator(byhour=range(24), interval = 24)
    monthsFmt = mpl.dates.DateFormatter('%Y-%m-%d %H:%M')

    fig = plt.figure(figsize=(2*11.7, 2*8.27))
    colors_y1 = CreateColors.main(hi=100, hf=110, numbcolors = (len(y1)-1))
    colors_y3 = CreateColors.main(hi=70, hf=80, numbcolors = (len(y3)))
    lbl_y = []
    if lbl_y2 <> '':
        lbl_y.append(lbl_y2)
    for i in range(len(lbl_y1)):
        lbl_y.append(lbl_y1[i])
    for i in range(len(lbl_y3)):
        lbl_y.append(lbl_y3[i])

    ax2=plt.subplot(111)
    ax2.set_title(strTitle)
    plt.setp( ax2.get_xticklabels(), fontsize=8)
    plt.setp( ax2.get_yticklabels(), fontsize=8)
    if y2<>[]:
        plt.plot_date(x,y2,'-', color='blue')
    plt.plot_date(x,y1[0],'-', color='green')
    for i in range(1,len(y1)):
        plt.plot_date(x,y1[i],'-.', color=colors_y1[i-1], linewidth = 2)
    if y3<>[]:
        for i in range(len(y3)):
            plt.plot_date(x,y3[i],'-.', color=colors_y3[i], linewidth = 2)
    ax2.yaxis.set_major_formatter(mpl.ticker.FormatStrFormatter('%1.2f'))
    labels=ax2.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    labels=ax2.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax2.xaxis.set_major_locator(locX)
    ax2.xaxis.set_major_formatter(monthsFmt)
    plt.xlim(x[0]-1.0,x[len(x)-1]+1.0)
    plt.ylabel('mm/day')
    plt.legend(lbl_y, loc=0)
    leg = plt.gca().get_legend()
    ltext  = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')    # the legend text fontsize
    plt.xlabel(r'Date')
    plt.grid(True)

    plt.subplots_adjust(left=0.05, bottom=0.1, right=0.95, top=0.95, wspace=0.1, hspace=0.05)
    if MMsurf_plot == 1:
        plt.show(block = True)
    elif MMsurf_plot == 0:
        plt.savefig(plot_exportPET_fn,dpi=150)
    else:
        print '\nWARNING!\nMMsurf_plot should be iqual to 0 or to 1! Plot saved anyway at %s' % plot_exportPET_fn
        plt.savefig(plot_exportPET_fn,dpi=150)
    plt.close()
    del fig
Exemplo n.º 2
0
def plot(x, y1, \
        y2 = [], y3 = [], y4 = [],\
        lbl_y1 = '', lbl_y2 = '', lbl_y3 = '', lbl_y4 = '', lbl_veg = ''
        ,plot_exportRF_fn = ''
        , MMsurf_plot = 0,
        strTitle = 'Title'
        ):

    ##    if len(x)>365:
    ##        locX = mpl.dates.MonthLocator()
    ##    else:
    ##        locX = mpl.dates.HourLocator(byhour=range(24), interval = 24)
    monthsFmt = mpl.dates.DateFormatter('%Y-%m-%d %H:%M')

    colors_y3 = CreateColors.main(hi=120, hf=130, numbcolors=(len(y3)))
    colors_y4 = CreateColors.main(hi=160, hf=180, numbcolors=(len(y4)))
    lbls_y3 = [lbl_y3 + " " + lbl for lbl in lbl_veg]
    lbls_y4 = [lbl_y4 + " " + lbl for lbl in lbl_veg]

    fig = plt.figure(figsize=(2 * 11.7, 2 * 8.27))
    ax1 = fig.add_subplot(4, 1, 4)
    ax1.xaxis_date()
    plt.setp(ax1.get_xticklabels(), fontsize=8)
    plt.setp(ax1.get_yticklabels(), fontsize=8)
    plt.bar(x,
            y1,
            color='b',
            linewidth=0,
            align='edge',
            width=0.8,
            label=lbl_y1)
    #    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels = ax1.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    labels = ax1.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax1.xaxis.set_major_locator(locX)
    ax1.xaxis.set_major_formatter(monthsFmt)
    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    lbls_y1 = []
    lbls_y1.append(lbl_y1)
    plt.legend(loc=0)
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')  # the legend text fontsize
    plt.xlabel(r'Date')
    plt.grid(True)

    ax2 = fig.add_subplot(4, 1, 3, sharex=ax1)
    ax2.xaxis_date()
    plt.setp(ax2.get_xticklabels(), visible=False)
    plt.setp(ax2.get_yticklabels(), fontsize=8)
    for i, (y, color, lbl) in enumerate(zip(y4, colors_y4, lbls_y4)):
        ax2.bar(x + (0.8 * float(i) / len(y4)),
                y,
                color=color,
                label=lbl,
                linewidth=0,
                align='edge',
                width=(0.8 / len(y4)))
#    ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels = ax2.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    #    ax2.set_xticks(x+(0.4/len(y4)))
    labels = ax2.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax2.xaxis.set_major_locator(locX)
    ax2.xaxis.set_major_formatter(monthsFmt)
    ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    plt.legend(loc=0)
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')  # the legend text fontsize
    plt.grid(True)

    ax3 = fig.add_subplot(4, 1, 2, sharex=ax1)
    ax3.xaxis_date()
    plt.setp(ax3.get_xticklabels(), visible=False)
    plt.setp(ax3.get_yticklabels(), fontsize=8)
    plt.bar(x,
            y2,
            color='aqua',
            linewidth=0,
            align='edge',
            width=0.8,
            label=lbl_y2)
    #    ax3.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels = ax3.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    labels = ax3.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax3.xaxis.set_major_locator(locX)
    ax3.xaxis.set_major_formatter(monthsFmt)
    ax3.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    lbls_y2 = []
    lbls_y2.append(lbl_y2)
    plt.legend(loc=0)
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')  # the legend text fontsize
    plt.grid(True)

    ax4 = fig.add_subplot(4, 1, 1, sharex=ax1)
    ax4.xaxis_date()
    ax4.set_title(strTitle)
    plt.setp(ax4.get_xticklabels(), visible=False)
    plt.setp(ax4.get_yticklabels(), fontsize=8)
    for i, (y, color, lbl) in enumerate(zip(y3, colors_y3, lbls_y3)):
        ax4.bar(x + (0.8 * float(i) / len(y3)),
                y,
                color=color,
                label=lbl,
                linewidth=0,
                align='edge',
                width=(0.8 / len(y3)))
#    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels = ax4.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    #    ax4.set_xticks(x+(0.4/len(y3)))
    labels = ax4.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax4.xaxis.set_major_locator(locX)
    ax4.xaxis.set_major_formatter(monthsFmt)
    ax4.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    plt.legend(loc=0)
    leg = plt.gca().get_legend()
    ltext = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')  # the legend text fontsize
    plt.grid(True)
    plt.xlim(x[0] - 1.0, x[len(x) - 1] + 1.0)

    plt.subplots_adjust(left=0.05,
                        bottom=0.1,
                        right=0.95,
                        top=0.95,
                        wspace=0.1,
                        hspace=0.15)
    if MMsurf_plot == 1:
        plt.show(block=True)
    elif MMsurf_plot == 0:
        plt.savefig(plot_exportRF_fn, dpi=150)
    else:
        print '\nWARNING!\nMMsurf_plot should be iqual to 0 or to 1! Plot saved anyway at %s' % plot_exportRF_fn
        plt.savefig(plot_exportRF_fn, dpi=150)
    plt.close()
    del fig


# EOF
#############################
Exemplo n.º 3
0
def plot(x, y1, \
        y2 = [], y3 = [], y4 = [],\
        lbl_y1 = '', lbl_y2 = '', lbl_y3 = '', lbl_y4 = '', lbl_veg = ''
        ,plot_exportRF_fn = ''
        , MMsurf_plot = 0,
        strTitle = 'Title'
        ):

##    if len(x)>365:
##        locX = mpl.dates.MonthLocator()
##    else:
##        locX = mpl.dates.HourLocator(byhour=range(24), interval = 24)
    monthsFmt = mpl.dates.DateFormatter('%Y-%m-%d %H:%M')

    colors_y3 = CreateColors.main(hi=120, hf=130, numbcolors = (len(y3)))
    colors_y4 = CreateColors.main(hi=160, hf=180, numbcolors = (len(y4)))
    lbls_y3 = [lbl_y3 + " " +  lbl for lbl in lbl_veg]
    lbls_y4 = [lbl_y4 + " " +  lbl for lbl in lbl_veg]

    fig = plt.figure(figsize=(2*11.7, 2*8.27))
    ax1=fig.add_subplot(4,1,4)
    ax1.xaxis_date()
    plt.setp( ax1.get_xticklabels(), fontsize=8)
    plt.setp( ax1.get_yticklabels(), fontsize=8)
    plt.bar( x, y1, color='b', linewidth = 0, align='edge', width = 0.8, label=lbl_y1)
#    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels=ax1.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    labels=ax1.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax1.xaxis.set_major_locator(locX)
    ax1.xaxis.set_major_formatter(monthsFmt)
    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    lbls_y1 = []
    lbls_y1.append(lbl_y1)
    plt.legend(loc = 0)
    leg = plt.gca().get_legend()
    ltext  = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')    # the legend text fontsize
    plt.xlabel(r'Date')
    plt.grid(True)

    ax2=fig.add_subplot(4,1,3, sharex=ax1)
    ax2.xaxis_date()
    plt.setp( ax2.get_xticklabels(), visible=False)
    plt.setp( ax2.get_yticklabels(), fontsize=8)
    for i, (y, color, lbl) in enumerate(zip(y4, colors_y4, lbls_y4)) :
        ax2.bar(x+(0.8*float(i)/len(y4)), y, color=color, label=lbl, linewidth=0, align='edge', width=(0.8/len(y4)))
#    ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels=ax2.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
#    ax2.set_xticks(x+(0.4/len(y4)))
    labels=ax2.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax2.xaxis.set_major_locator(locX)
    ax2.xaxis.set_major_formatter(monthsFmt)
    ax2.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    plt.legend(loc = 0)
    leg = plt.gca().get_legend()
    ltext  = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')    # the legend text fontsize
    plt.grid(True)

    ax3=fig.add_subplot(4,1,2, sharex=ax1)
    ax3.xaxis_date()
    plt.setp( ax3.get_xticklabels(), visible=False)
    plt.setp( ax3.get_yticklabels(), fontsize=8)
    plt.bar(x,y2,color='aqua', linewidth=0, align='edge', width = 0.8, label=lbl_y2)
#    ax3.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels=ax3.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
    labels=ax3.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax3.xaxis.set_major_locator(locX)
    ax3.xaxis.set_major_formatter(monthsFmt)
    ax3.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    lbls_y2 = []
    lbls_y2.append(lbl_y2)
    plt.legend(loc = 0)
    leg = plt.gca().get_legend()
    ltext  = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')    # the legend text fontsize
    plt.grid(True)

    ax4=fig.add_subplot(4,1,1, sharex=ax1)
    ax4.xaxis_date()
    ax4.set_title(strTitle)
    plt.setp( ax4.get_xticklabels(), visible=False)
    plt.setp( ax4.get_yticklabels(), fontsize=8)
    for i, (y, color, lbl) in enumerate(zip(y3, colors_y3, lbls_y3)) :
        ax4.bar(x+(0.8*float(i)/len(y3)), y, color=color, label=lbl, linewidth=0, align='edge', width=(0.8/len(y3)))
#    ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%1.2f'))
    labels=ax4.get_yticklabels()
    plt.setp(labels, 'rotation', 90)
#    ax4.set_xticks(x+(0.4/len(y3)))
    labels=ax4.get_xticklabels()
    plt.setp(labels, 'rotation', 90)
    #ax4.xaxis.set_major_locator(locX)
    ax4.xaxis.set_major_formatter(monthsFmt)
    ax4.yaxis.set_major_formatter(plt.FormatStrFormatter('%0.1f'))
    plt.legend(loc = 0)
    leg = plt.gca().get_legend()
    ltext  = leg.get_texts()  # all the text.Text instance in the legend
    plt.setp(ltext, fontsize='small')    # the legend text fontsize
    plt.grid(True)
    plt.xlim(x[0]-1.0,x[len(x)-1]+1.0)

    plt.subplots_adjust(left=0.05, bottom=0.1, right=0.95, top=0.95, wspace=0.1, hspace=0.15)
    if MMsurf_plot == 1:
        plt.show(block = True)
    elif MMsurf_plot == 0:
        plt.savefig(plot_exportRF_fn,dpi=150)
    else:
        print '\nWARNING!\nMMsurf_plot should be iqual to 0 or to 1! Plot saved anyway at %s' % plot_exportRF_fn
        plt.savefig(plot_exportRF_fn,dpi=150)
    plt.close()
    del fig
# EOF
#############################