Beispiel #1
0
def draw_histogram(filename,
                   dvalues,
                   titledict=None,
                   tl_list=None,
                   tr_list=None,
                   bins=200,
                   ranges=None,
                   label='Hist'):
    """
    画直方图
    """
    plt.style.use(os.path.join(dvPath, 'dv_pub_regression.mplstyle'))

    alpha = 1
    fig = plt.figure(figsize=(6, 4))
    fig.subplots_adjust(top=0.92, bottom=0.13, left=0.11, right=0.96)

    ax = plt.gca()
    ax.grid(True)

    ax.hist(dvalues,
            bins,
            histtype='bar',
            color='blue',
            label=label,
            alpha=alpha)

    ax.legend(prop={'size': 10})

    add_annotate(ax, tl_list, 'left')
    add_annotate(ax, tr_list, 'right')
    add_title(titledict)
    set_tick_font(ax)

    plt.savefig(filename)
    fig.clear()
    plt.close()
Beispiel #2
0
def plot_tbbias(date_D, bias_D, date_M, bias_M, picPath, title, date_s, date_e,
                satName):
    '''
    画偏差时序折线图
    '''
    fig = plt.figure(figsize=(6, 4))
    #     plt.subplots_adjust(left=0.13, right=0.95, bottom=0.11, top=0.97)

    if (np.isnan(bias_D)).all():
        Log.error('Everything is NaN: %s' % picPath)
        return

    plt.plot(date_D,
             bias_D,
             'x',
             ms=6,
             markerfacecolor=None,
             markeredgecolor=BLUE,
             alpha=0.8,
             mew=0.3,
             label='Daily')

    plt.plot(date_M, bias_M, 'o-', ms=5, lw=0.6, c=RED, mew=0, label='Monthly')
    plt.grid(True)
    plt.ylabel('DTB($K$)', fontsize=11, fontproperties=FONT0)

    xlim_min = pb_time.ymd2date('%04d%02d01' % (date_s.year, date_s.month))
    xlim_max = date_e
    plt.xlim(xlim_min, xlim_max)
    if "FY2" in satName:
        plt.ylim(-8, 8)
    elif "FY3" in satName:
        plt.ylim(-8, 8)
    elif "FY4" in satName:
        plt.ylim(-2, 2)

    ax = plt.gca()
    # format the ticks
    setXLocator(ax, xlim_min, xlim_max)
    set_tick_font(ax)

    # title
    plt.title(title, fontsize=12, fontproperties=FONT0)

    plt.tight_layout()
    #--------------------
    fig.subplots_adjust(bottom=0.2)

    circle1 = mpatches.Circle((74, 15), 6, color=BLUE, ec=EDGE_GRAY, lw=0)
    circle2 = mpatches.Circle((164, 15), 6, color=RED, ec=EDGE_GRAY, lw=0)
    fig.patches.extend([circle1, circle2])

    fig.text(0.15, 0.02, 'Daily', color=BLUE, fontproperties=FONT0)
    fig.text(0.3, 0.02, 'Monthly', color=RED, fontproperties=FONT0)

    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.50, 0.02, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.50, 0.02, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.8, 0.02, ORG_NAME, fontproperties=FONT0)
    #---------------
    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    plt.savefig(picPath)
    fig.clear()
    plt.close()
def plot_tbbias(date_D, bias_D, date_M, bias_M, picPath, title, date_s, date_e):
    """
    画偏差时序折线图
    """
    plt.style.use(os.path.join(DV_PATH, 'dv_pub_timeseries.mplstyle'))
    fig = plt.figure(figsize=(6, 4))
#     plt.subplots_adjust(left=0.13, right=0.95, bottom=0.11, top=0.97)

    if (np.isnan(bias_D)).all():
        Log.error('Everything is NaN: %s' % picPath)
        return

    plt.plot(date_D, bias_D, 'x', ms=6,
             markerfacecolor=None, markeredgecolor=BLUE, alpha=0.8,
             mew=0.3, label='Daily')

    plt.plot(date_M, bias_M, 'o-', ms=5, lw=0.6, c=RED,
             mew=0, label='Monthly')
    plt.grid(True)
    plt.ylabel('DTB($K$)', fontsize=11, fontproperties=FONT0)

    xlim_min = date_s
    xlim_max = date_e
    plt.xlim(xlim_min, xlim_max)
    plt.ylim(-1, 1)

    # 画 y=0 线
    plt.plot([xlim_min, xlim_max], [0, 0], color='#808080',
             linewidth=1.0)

    ax = plt.gca()
    # format the ticks
    setXLocator(ax, xlim_min, xlim_max)
    set_tick_font(ax)
    ax.yaxis.set_major_locator(MultipleLocator(0.25))
    ax.yaxis.set_minor_locator(MultipleLocator(0.125))

    # title
    plt.title(title, fontsize=12, fontproperties=FONT0)

    plt.tight_layout()
    #--------------------
    fig.subplots_adjust(bottom=0.2)

    circle1 = mpatches.Circle((74, 15), 6, color=BLUE, ec=EDGE_GRAY, lw=0)
    circle2 = mpatches.Circle((164, 15), 6, color=RED, ec=EDGE_GRAY, lw=0)
    fig.patches.extend([circle1, circle2])

    fig.text(0.15, 0.02, 'Daily', color=BLUE, fontproperties=FONT0)
    fig.text(0.3, 0.02, 'Monthly', color=RED, fontproperties=FONT0)

    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.50, 0.02, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.50, 0.02, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.8, 0.02, ORG_NAME, fontproperties=FONT0)
    #---------------
    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    plt.savefig(picPath)
    fig.clear()
    plt.close()
Beispiel #4
0
def plot_bias(date_D, bias_D, date_M, bias_M, picPath, title, date_s, date_e,
              each, date_type, ylim_min, ylim_max):
    """
    画偏差时序折线图
    """
    plt.style.use(os.path.join(dvPath, 'dv_pub_timeseries.mplstyle'))
    fig = plt.figure(figsize=(6, 4))
    #     plt.subplots_adjust(left=0.13, right=0.95, bottom=0.11, top=0.97)

    plt.plot(date_D,
             bias_D,
             'x',
             ms=6,
             markerfacecolor=None,
             markeredgecolor=BLUE,
             alpha=0.8,
             mew=0.3,
             label='Daily')
    plt.plot(date_M, bias_M, 'o-', ms=5, lw=0.6, c=RED, mew=0, label='Monthly')

    plt.grid(True)
    plt.ylabel('%s %s' % (each, date_type), fontsize=11, fontproperties=FONT0)

    xlim_min = pb_time.ymd2date('%04d%02d01' % (date_s.year, date_s.month))
    xlim_max = date_e

    plt.plot([xlim_min, xlim_max], [0, 0], '#808080')  # 在 y=0 绘制一条深灰色直线

    plt.xlim(xlim_min, xlim_max)
    plt.ylim(ylim_min, ylim_max)

    ax = plt.gca()
    # format the ticks
    interval = (ylim_max - ylim_min) / 8  # 8 个间隔
    minibar = interval / 2.
    setXLocator(ax, xlim_min, xlim_max)
    set_tick_font(ax)

    # 如果范围为浮点数,需要进行一次格式化,否则图像不会显示最后一个刻度
    if isinstance(interval, float):
        interval = float('%.5f' % interval)
        minibar = float('%.5f' % minibar)

    ax.yaxis.set_major_locator(MultipleLocator(interval))
    ax.yaxis.set_minor_locator(MultipleLocator(minibar))

    # title
    plt.title(title, fontsize=12, fontproperties=FONT0)

    plt.tight_layout()
    # --------------------
    fig.subplots_adjust(bottom=0.2)

    circle1 = mpatches.Circle((74, 15), 6, color=BLUE, ec=EDGE_GRAY, lw=0)
    circle2 = mpatches.Circle((164, 15), 6, color=RED, ec=EDGE_GRAY, lw=0)
    fig.patches.extend([circle1, circle2])

    fig.text(0.15, 0.02, 'Daily', color=BLUE, fontproperties=FONT0)
    fig.text(0.3, 0.02, 'Monthly', color=RED, fontproperties=FONT0)

    ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d')
    if ymd_s != ymd_e:
        fig.text(0.50, 0.02, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0)
    else:
        fig.text(0.50, 0.02, '%s' % ymd_s, fontproperties=FONT0)

    fig.text(0.8, 0.02, ORG_NAME, fontproperties=FONT0)
    # ---------------
    pb_io.make_sure_path_exists(os.path.dirname(picPath))
    plt.savefig(picPath)
    fig.clear()
    plt.close()