def plot_abc(date_D, a_D, b_D, c_D, date_M, a_M, b_M, c_M, picPath, title, date_s, date_e, var): fig = plt.figure(figsize=(6, 6)) ax1 = plt.subplot(311) ax2 = plt.subplot(312, sharex=ax1) ax3 = plt.subplot(313, sharex=ax1) # format the Xticks xlim_min = pb_time.ymd2date('%04d%02d01' % (date_s.year, date_s.month)) xlim_max = date_e ax1.set_xlim(xlim_min, xlim_max) # format the Yticks\ if var == "tbb-tbb" or var == "ref-ref": ax1.set_ylim(0, 2) ax1.yaxis.set_major_locator(MultipleLocator(0.5)) ax1.yaxis.set_minor_locator(MultipleLocator(0.1)) elif var == "dn-ref": ax1.set_ylim(0.0002, 0.0007) ax1.yaxis.set_major_locator(MultipleLocator(0.0001)) ax1.yaxis.set_minor_locator(MultipleLocator(0.00005)) if var == "tbb-tbb": ax2.set_ylim(-30, 30) ax2.yaxis.set_major_locator(MultipleLocator(10)) ax2.yaxis.set_minor_locator(MultipleLocator(2)) elif var == "ref-ref": ax2.set_ylim(-0.1, 0.1) ax2.yaxis.set_major_locator(MultipleLocator(0.02)) ax2.yaxis.set_minor_locator(MultipleLocator(0.01)) elif var == "dn-ref": ax2.set_ylim(-0.08, 0.08) ax2.yaxis.set_major_locator(MultipleLocator(0.02)) ax2.yaxis.set_minor_locator(MultipleLocator(0.01)) ax3.set_ylim(0, 7) ax3.yaxis.set_major_locator(MultipleLocator(1)) ax3.yaxis.set_minor_locator(MultipleLocator(0.2)) # plot ax1 ------------------------------------------------- plt.sca(ax1) plt.plot(date_D, a_D, 'x', ms=5, markerfacecolor=None, markeredgecolor=BLUE, alpha=0.8, mew=0.3, label='Daily') plt.plot(date_M, a_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly') plt.ylabel('Slope', fontsize=11, fontproperties=FONT0) plt.grid(True) plt.title(title, fontsize=12, fontproperties=FONT0) set_tick_font(ax1) plt.setp(ax1.get_xticklabels(), visible=False) # plot ax2 ------------------------------------------------- plt.sca(ax2) plt.plot(date_D, b_D, 'x', ms=5, markerfacecolor=None, markeredgecolor=BLUE, alpha=0.8, mew=0.3, label='Daily') plt.plot(date_M, b_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly') plt.ylabel('Intercept', fontsize=11, fontproperties=FONT0) plt.grid(True) set_tick_font(ax2) plt.setp(ax2.get_xticklabels(), visible=False) # point number ------------------------------------------------- plt.sca(ax3) plt.fill_between(date_D, 0, c_D, edgecolor=BLUE, facecolor=BLUE, alpha=0.6) # plt.fill_between(date_M, 0, c_M, # edgecolor=RED, facecolor=RED, alpha=0.5) # plt.bar(date_M, c_M, width=1, align='edge', # "center", # color=RED, linewidth=0) plt.plot(date_M, c_M, 'o-', ms=4, lw=0.6, c=RED, mew=0, label='Monthly') plt.ylabel('Number of sample points\nlog (base = 10)', fontsize=11, fontproperties=FONT0) plt.grid(True) set_tick_font(ax3) setXLocator(ax3, xlim_min, xlim_max) # circle1 = mpatches.Circle((430, 563), 5, color=BLUE, ec=EDGE_GRAY, lw=0) # circle2 = mpatches.Circle((508, 563), 5, color=RED, ec=EDGE_GRAY, lw=0) # fig.patches.extend([circle1, circle2]) # # fig.text(0.74, 0.93, 'Daily', color=BLUE, fontproperties=FONT0) # fig.text(0.86, 0.93, 'Monthly', color=RED, fontproperties=FONT0) #--------------- plt.tight_layout() fig.subplots_adjust(bottom=0.14) circle1 = mpatches.Circle((74, 18), 6, color=BLUE, ec=EDGE_GRAY, lw=0) circle2 = mpatches.Circle((164, 18), 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)) fig.savefig(picPath) plt.close() fig.clear
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_rmd(date_d, data_d, date_m, data_m, std_m, pic_path, date_s, date_e, sat_name, pair, chan, day_or_night, ref_temp, xname, xname_l, xunit, yname, yname_l, yunit, ): if (np.isnan(data_d)).all(): Log.error('Everything is NaN: %s' % pic_path) return plt.style.use(os.path.join(DV_PATH, 'dv_pub_timeseries.mplstyle')) fig = plt.figure(figsize=(6, 4)) # fig.subplots_adjust(top=0.88, bottom=0.11, left=0.12, right=0.97) ax1 = plt.subplot2grid((1, 1), (0, 0)) # 设置 title 参数 part1, part2 = pair.split('_') title = 'Time Series of REF Relative Bias \n{} Minus {} {} {} REF={}'.format( part1, part2, chan, day_or_night, ref_temp) # plot timeseries -------------------------------------------------------- timeseries_xmin = pb_time.ymd2date( '%04d%02d01' % (date_s.year, date_s.month)) timeseries_xmax = date_e if "FY2" in sat_name: timeseries_ymin = -20 timeseries_ymax = 20 elif "FY3" in sat_name: timeseries_ymin = -20 timeseries_ymax = 20 elif "FY4" in sat_name: timeseries_ymin = -20 timeseries_ymax = 20 else: timeseries_ymin = None timeseries_ymax = None timeseries_axislimit = { "xlimit": (timeseries_xmin, timeseries_xmax), "ylimit": (timeseries_ymin, timeseries_ymax), } # x y 轴标签 timeseries_label = {} if xunit != "": ylabel = 'Relative Bias {}'.format(xunit) else: ylabel = "Relative Bias %" timeseries_label["ylabel"] = ylabel # x, y 轴大刻度的数量,和小刻度的数量 timeseries_locator = {"locator_x": (None, None), "locator_y": (8, 2)} # y=0 线配置 timeseries_zeroline = {"line_color": '#808080', "line_width": 1.0} timeseries_daily = { "marker": 'x', "color": BLUE, "linewidth": None, "markersize": 6, "markerfacecolor": None, "markeredgecolor": BLUE, "alpha": 0.8, "markeredgewidth": 0.3, "label": "Daily", } dv_pub_3d.draw_timeseries( ax1, date_d, data_d, label=timeseries_label, axislimit=timeseries_axislimit, locator=timeseries_locator, zeroline=timeseries_zeroline, timeseries=timeseries_daily, ) timeseries_monthly = { "marker": 'o-', "color": RED, "linewidth": 0.6, "markersize": 5, "markerfacecolor": None, "markeredgecolor": RED, "alpha": 0.8, "markeredgewidth": 0, "label": "Monthly", } background_fill_timeseries = { 'x': date_m, 'y': data_m - std_m, 'y1': data_m + std_m, "color": RED, } dv_pub_3d.draw_timeseries( ax1, date_m, data_m, label=timeseries_label, axislimit=timeseries_axislimit, locator=timeseries_locator, zeroline=timeseries_zeroline, timeseries=timeseries_monthly, background_fill=background_fill_timeseries, ) # -------------------- plt.tight_layout() fig.suptitle(title, fontsize=11, fontproperties=FONT0) fig.subplots_adjust(bottom=0.2, top=0.88) 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(pic_path)) plt.savefig(pic_path) print pic_path 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()
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()