def plot_events(drop, e_drop, mtbf, e_mtbf, latency, e_rtt, hb, e_pmet, hbfreq): (fig, ax) = plt.subplots() # Turn mtbf into a step function mtbf_step_t = np.zeros((mtbf.shape[0] * 2)) mtbf_step_v = np.zeros((mtbf.shape[0] * 2)) mtbf_step_t[::2] = mtbf[:, 0] mtbf_step_t[1:-1:2] = mtbf[1:, 0] mtbf_step_t[-1] = mtbf[-1, 0] + CHANGE_DELAY mtbf_step_v[::2] = mtbf[:, 1] mtbf_step_v[1::2] = mtbf[:, 1] # Turn latency into a step function latency_step_t = np.zeros((latency.shape[0] * 2)) latency_step_v = np.zeros((latency.shape[0] * 2)) latency_step_t[::2] = latency[:, 0] latency_step_t[1:-1:2] = latency[1:, 0] latency_step_t[-1] = latency[-1, 0] + CHANGE_DELAY latency_step_v[::2] = latency[:, 1] latency_step_v[1::2] = latency[:, 1] # Plot actual MTBF and latency ax.plot(mtbf_step_t, mtbf_step_v, color=cb2[0], label="Actual MTBF") ax.plot(latency_step_t, latency_step_v, color=cb2[1], label="Actual Latency") ax.axvline(drop[0, 0], ls=":", color="k", alpha=0.2, label="Node drops") for (t, _) in drop[1:]: ax.axvline(t, ls=":", color="k", alpha=0.2) # Plot mtbf_ and rtt_estimate_ ax.plot(e_mtbf[:, 0], e_mtbf[:, 1] / 1000.0, color=cb2[4], label="Estimated MTBF") ax.plot(e_rtt[:, 0], e_rtt[:, 1] / 2000.0, color=cb2[5], label="Estimated Latency") # Overlay the estimated, theoretical, and measured policy metric axG = ax.twinx() axG.plot(e_pmet[:, 0], e_pmet[:, 1], color=cb2[7], label="Estimated PMetric") pmet = np.empty(e_pmet.shape) pmet[:, 0] = e_pmet[:, 0] T_hb = 280.0 # program constant T_bf = np.interp(pmet[:, 0], mtbf_step_t, mtbf_step_v) T_to = 880.0 # program constant T_l = np.interp(pmet[:, 0], latency_step_t, latency_step_v) C_r = 20.0 # approximation for cost of recovery C_hb = 2.0 # approximation for cost of one heartbeat # print ( F_hb, F_mf, T_to, T_l, C_r, C_hb ) pmet[:, 1] = goodplot.pmetric(T_hb, T_bf, T_to, T_l, C_r, C_hb) axG.plot(pmet[:, 0], pmet[:, 1], color=cb2[3], label="Theoretical PMetric") # FIXME: empirical pmet # Polish off plot t_max = max( np.max(drop[:, 0]), np.max(e_drop[:, 0]), np.max(mtbf[:, 0]), np.max(e_mtbf[:, 0]), np.max(latency[:, 0]), np.max(e_rtt[:, 0]), np.max(hb[:, 0]), ) ax.set_xlim((0, t_max)) ax.set_xlabel(r"Time") ax.set_ylabel(r"Latency and MTBF (ms)") axG.set_ylabel(r"PMetric") ax.set_title("Tracking policy accuracy") # ax.legend(loc=2) # axG.legend() fig.tight_layout() return (fig, ax)
rcParams['patch.facecolor'] = cb2[0] rcParams['font.family'] = 'Helvetica' rcParams['font.weight'] = 100 # ^^^^^ MPL Boilerplate ^^^^^ ################################################################################ import goodplot if __name__=='__main__': #T_hb = 280. T_bf = 1000. # MTBF (ms) #T_to = 1000. # master timeout, in ms #T_l = 150. # latency, in ms C_r = 20. # recovery cost, in packets C_hb = 2. # heartbeat cost, in packets T_l = (np.linspace(50,500,200)) (fig,ax) = plt.subplots() for T_hb in np.linspace(50,800,8): for T_to in np.linspace(800,1600,8): p = goodplot.pmetric(T_hb, T_bf, T_to, T_l, C_r, C_hb) ax.plot(T_l, p, label=r'$T_{to}$='+str(T_to)) #ax.axvline(T_bf,color='k',label=r'$T_{bf}$') ax.set_xlabel(r'Latency ($T_{l}$)') ax.set_ylabel('PMetric') #ax.legend() fig.savefig('lat.png')