def plot_omb(date_D, a_D, b_D, picPath, title, date_s, date_e): ''' 画偏差时序彩色图 ''' if (np.isnan(a_D)).all(): Log.error('Everything is NaN: %s' % picPath) return ylim_min, ylim_max = 210, 330 y_res = 0.2 x_size = (date_e - date_s).days yy = np.arange(ylim_min, ylim_max, y_res) + y_res / 2. # 一列的y值 grid = np.ones(len(date_D)) * yy.reshape(-1, 1) aa = a_D * np.ones((len(grid), 1)) bb = b_D * np.ones((len(grid), 1)) grid = grid - np.divide((grid - bb), aa) zz = np.zeros((len(yy), x_size)) # 2D, 要画的值 j = 0 xx = [] # 一行的x值 for i in xrange(x_size): # 补充缺失数据的天 date_i = date_s + relativedelta(days=i) xx.append(date_i) if j < len(date_D) and date_D[j] == date_i: zz[:, i] = grid[:, j] j = j + 1 fig = plt.figure(figsize=(6, 4)) ax = fig.add_subplot(111) norm = mpl.colors.Normalize(vmin=-10.0, vmax=10.0) xx = np.array(xx) plt.pcolormesh(xx, yy, zz, cmap='jet', norm=norm, shading='gouraud', zorder=0) plt.grid(True, zorder=10) xlim_min = date_s xlim_max = date_e plt.xlim(xlim_min, xlim_max) plt.ylim(ylim_min, ylim_max) plt.ylabel('TB($K$)', fontsize=11, fontproperties=FONT0) # 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.25) # -------add colorbar --------- fig.canvas.draw() point_bl = ax.get_position().get_points()[0] # 左下 point_tr = ax.get_position().get_points()[1] # 右上 cbar_height = 0.05 colorbar_ax = fig.add_axes([ point_bl[0] - 0.05, 0.05, (point_tr[0] - point_bl[0]) / 2.2, cbar_height ]) mpl.colorbar.ColorbarBase(colorbar_ax, cmap='jet', norm=norm, orientation='horizontal') # ---font of colorbar----------- for l in colorbar_ax.xaxis.get_ticklabels(): l.set_fontproperties(FONT0) l.set_fontsize(9) # ------Time and ORG_NAME---------------- ymd_s, ymd_e = date_s.strftime('%Y%m%d'), date_e.strftime('%Y%m%d') if ymd_s != ymd_e: fig.text(0.52, 0.05, '%s-%s' % (ymd_s, ymd_e), fontproperties=FONT0) else: fig.text(0.52, 0.05, '%s' % ymd_s, fontproperties=FONT0) fig.text(0.82, 0.05, 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()
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_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()