def plot_relative(src_gst_latency, src_src_latency, src_pos):
    triu = np.triu_indices(src_gst_latency.shape[0], 1)
    ixp_routed = np.around(src_gst_latency[triu], 6)
    city_gst = np.around(src_src_latency[triu], 6)

    pairwise_src = DistanceMetric.pairwise(
        DistanceMetric.get_metric("haversine"), np.deg2rad(src_pos),
        np.deg2rad(src_pos))
    pairwise_src = pairwise_src * EARTH_RADIUS

    percent = (ixp_routed - city_gst) / city_gst * 100
    pairwise = pairwise_src[triu]

    vals, avg_c, min_c, max_c, percent = vector_map_statistics(
        pairwise, percent, 100, [25, 75])
    colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
    cur_color = colors[0]

    plt.figure(figsize=(8, 6))
    gs1 = gridspec.GridSpec(2, 1)
    gs1.update(wspace=0.01, hspace=0.11)  # set the spacing between axes.

    axes = [plt.subplot(gs1[0]), plt.subplot(gs1[1])]

    axes[0].axhline(0, c='grey', linewidth=0.5)
    axes[0].semilogy(vals, avg_c, label="Average", c=cur_color, linewidth=3)
    axes[0].semilogy(vals,
                     percent[25],
                     "--",
                     label="Quartiles",
                     c=cur_color,
                     linewidth=3)
    axes[0].semilogy(vals, percent[75], "--", c=cur_color, linewidth=3)
    axes[0].plot(vals,
                 max_c,
                 ":",
                 linewidth=3,
                 label="Min-max variability",
                 c=cur_color)
    axes[0].set_ylim(90, 1000)
    axes[0].set_ylabel("log-scale")
    axes[0].set_xticks([])
    axes[0].legend()

    axes[1].axhline(0, c='grey', linewidth=0.5)
    axes[1].plot(vals,
                 avg_c,
                 label="Average city-city",
                 c=cur_color,
                 linewidth=3)
    axes[1].plot(vals,
                 percent[25],
                 "--",
                 label="Quartiles",
                 c=cur_color,
                 linewidth=3)
    axes[1].plot(vals, percent[75], "--", c=cur_color, linewidth=3)
    axes[1].plot(vals,
                 max_c,
                 ":",
                 linewidth=3,
                 label="Min-max variability",
                 c=cur_color)
    axes[1].plot(vals,
                 min_c,
                 ":",
                 linewidth=3,
                 label="Min-max variability",
                 c=cur_color)
    axes[1].set_xlabel("SRC-DST great-circle distance (km)")
    axes[1].set_ylabel("Loss IXP deployment (%)")
    # axes[1].set_ylabel("Latency increase IXP deployment (%)")
    axes[1].set_ylim(-50, 90)

    plt.savefig("figures/percent-ixp-loss.png")
def plot_absolute(src_gst_latency, src_src_latency, src_pos):
    triu = np.triu_indices(src_gst_latency.shape[0], 1)
    ixp_routed = np.around(src_gst_latency[triu], 6)
    city_gst = np.around(src_src_latency[triu], 6)

    SCALING = 1e3

    plt.figure(figsize=(8, 6))
    pairwise_src = DistanceMetric.pairwise(
        DistanceMetric.get_metric("haversine"), np.deg2rad(src_pos),
        np.deg2rad(src_pos))
    pairwise_src = pairwise_src * EARTH_RADIUS

    pairwise = pairwise_src[triu]
    vals, avg_c, min_c, max_c, _ = vector_map_statistics(
        pairwise, city_gst, 10)

    avg_c = np.asarray(avg_c) * SCALING
    min_c = np.asarray(min_c) * SCALING
    max_c = np.asarray(max_c) * SCALING

    plt.plot(vals, avg_c, label="Average city-city", linewidth=3)
    plt.xlabel("SRC-DST distance (km)")
    plt.ylabel("Latency (s)")
    plt.legend(loc=2)

    pairwise = pairwise_src[triu]
    vals, avg_g, min_g, max_g, _ = vector_map_statistics(
        pairwise, ixp_routed, 10)

    avg_g = np.asarray(avg_g) * SCALING
    min_g = np.asarray(min_g) * SCALING
    max_g = np.asarray(max_g) * SCALING

    plt.plot(vals, avg_g, label="Average IXP-city", linewidth=3)

    plt.plot(vals,
             vals / LIGHT_IN_FIBER * SCALING,
             ':',
             linewidth=3,
             label="Great-circle in fiber")
    plt.plot(vals,
             vals / LIGHT_IN_VACUUM * SCALING,
             '--',
             label="Great-circle in vacuum",
             linewidth=3)
    plt.plot(vals,
             vals * FIBER_PATH_STRETCH / LIGHT_IN_FIBER * SCALING,
             '-.',
             label="Path-stretch in fiber",
             linewidth=3)

    plt.ylim(0, 150)
    plt.xlim(0, np.max(vals))

    plt.xlabel("SRC-DST great-circle distance (km)")
    plt.ylabel("One-way latency (s)")
    plt.legend(loc=9, ncol=2, mode="expand")

    # Save figures
    # plt.savefig("figures/latency-distance.pdf")
    plt.savefig("figures/latency-distance.png")