for i, scheduler in enumerate(no_error):
        no_error_data[i].append(np.array(res[scheduler]).mean())
    for i, scheduler in enumerate(with_error):
        with_error_data[i].append(np.array(res[scheduler]).mean())

figures = [("No error", float(0), no_error, no_error_data),
           (r"$\sigma={}$".format(args.sigma),
            args.sigma, with_error, with_error_data)]

for title, sigma, schedulers, data in figures:
    fig = plt.figure(title)
    ax = fig.add_subplot(111)
    plt.xlabel("$d/n$")
    plt.ylabel("mean sojourn time (s)")

    for scheduler, mst, style in zip(schedulers, data,
                                     plot_helpers.cycle_styles('x')):
        ax.semilogy(dns, mst, style, label=scheduler)
    ax.grid()
    handles, labels = ax.get_legend_handles_labels()
    lgd = ax.legend(handles, labels, loc=2, bbox_to_anchor=(1, 1))
    ax.grid('on')

    if args.for_paper:
        fmt = 'sojourn-vs-dn_{}_{}_{}.pdf'
        fname = fmt.format(args.dataset, sigma, args.load)
        plt.savefig(fname,bbox_extra_artists=(lgd,), bbox_inches='tight')

if not args.for_paper:
    plt.show()
    for i, scheduler in enumerate(no_error):
        no_error_data[i].append(np.array(res[scheduler]).mean())
    for i, scheduler in enumerate(with_error):
        with_error_data[i].append(np.array(res[scheduler]).mean())

figures = [("No error", float(0), no_error, no_error_data),
           (r"$\sigma={}$".format(args.sigma), args.sigma, with_error,
            with_error_data)]

for title, sigma, schedulers, data in figures:
    fig = plt.figure(title)
    ax = fig.add_subplot(111)
    plt.xlabel("$d/n$")
    plt.ylabel("mean sojourn time (s)")

    for scheduler, mst, style in zip(schedulers, data,
                                     plot_helpers.cycle_styles('x')):
        ax.semilogy(dns, mst, style, label=scheduler)
    ax.grid()
    handles, labels = ax.get_legend_handles_labels()
    lgd = ax.legend(handles, labels, loc=2, bbox_to_anchor=(1, 1))
    ax.grid('on')

    if args.for_paper:
        fmt = 'sojourn-vs-dn_{}_{}_{}.pdf'
        fname = fmt.format(args.dataset, sigma, args.load)
        plt.savefig(fname, bbox_extra_artists=(lgd, ), bbox_inches='tight')

if not args.for_paper:
    plt.show()
    res = shelve.open(fname, 'r')
    for i, scheduler in enumerate(no_error):
        no_error_data[i].append(np.array(res[scheduler]).mean())
    for i, scheduler in enumerate(with_error):
        with_error_data[i].append([r.mean() for r in res[scheduler]])

for scheduler, err_data in zip(with_error, with_error_data):
    fig = plt.figure(scheduler)
    ax = fig.add_subplot(111)
    plt.xlabel("$\sigma$")
    plt.ylabel("mean sojourn time (s)")
    xs = list(range(1, len(sigmas) + 1))
    xs[0] -= 1
    xs[-1] += 1
    for noerr_sched, noerr_data, style in zip(no_error, no_error_data,
                                              plot_helpers.cycle_styles()):
        ax.semilogy(xs, noerr_data, style, label=noerr_sched)
    ax.boxplot(err_data)
    plt.xticks(range(1, len(sigmas) + 1), sigmas)
    plt.ylim(min([min(d) for d in no_error_data]) * 0.85,
             max([max(d) for d in no_error_data]) / 0.85)
    handles, labels = ax.get_legend_handles_labels()
    lgd = ax.legend(handles, labels, loc=2, bbox_to_anchor=(1, 1))

    if args.for_paper:
        fmt = 'sojourn-vs-error_{}_{}_{}_{}.pdf'
        fname = fmt.format(scheduler, args.dataset, args.d_over_n, args.load)
        plt.savefig(fname,bbox_extra_artists=(lgd,), bbox_inches='tight')

if not args.for_paper:
    plt.show()
res = shelve.open(fname, 'r')
for scheduler in no_error:
    no_error_data.append(samples(res[scheduler]))
for scheduler in with_error:
    with_error_data.append(samples(res[scheduler]))

figures = [("No error", float(0), no_error, no_error_data),
           (r"$\sigma={}$".format(args.sigma), args.sigma, with_error,
            with_error_data)]

for title, sigma, schedulers, data in figures:
    plt.figure(title)
    plt.xlabel("Slowdown")
    plt.ylabel("ECDF")
    ys = np.linspace(1 / NPOINTS, 1, NPOINTS)

    for scheduler, xs, style in zip(schedulers, data,
                                    plot_helpers.cycle_styles()):
        # plot the CDF of results
        plt.semilogx(xs, ys, label=scheduler)
    plt.grid()
    plt.legend(loc=0)

    if args.for_paper:
        fmt = 'slowdown_{}_{}_{}_{}.pdf'
        fname = fmt.format(args.dataset, sigma, args.d_over_n, args.l)
        plt.savefig(fname)

if not args.for_paper:
    plt.show()