ax = plt.subplot(gs[0, :])
img = ax.pcolormesh(phi0s_plt,
                    delta_phi_fs,
                    t_opts_ref,
                    label='Time (h)',
                    cmap='inferno',
                    vmax=60,
                    vmin=0)
cbar = plt.colorbar(img)
img.set_zorder(-20)
cbar.set_label('$t^{opt}$ (h)')
ax.set_ylabel('$\Delta\phi_f$')
ax.set_rasterization_zorder(-10)
plo.format_2pi_axis(ax)
plo.format_4pi_axis(ax, x=False, y=True)
ax.set_ylim(0, 2 * np.pi)
ax.set_xticklabels([])

bx = plt.subplot(gs[1, :])
img = bx.pcolormesh(phi0s_plt,
                    delta_phi_fs,
                    t_opts_4h,
                    label='Time (h)',
                    cmap='inferno',
                    vmax=60,
                    vmin=0)
cbar = plt.colorbar(img)
img.set_zorder(-20)
cbar.set_label('$t^{opt}_{4h}$ (h)')
bx.set_ylabel('$\Delta\phi_f$')
def plot_subfig_results(axes, sfr, shift=0, pred_win=2):
    cx, dx, ex = axes
    control_inputs, errors, time_steps, mpc_phis, ext_phis_output, mpc_ps, mpc_ts, tphases, contphases = sfr

    def shift_time(ts, shift_t=1.75 * pmodel.T, shift_val=shift):
        if np.size(ts) is 1:
            if ts >= shift_t:
                return ts + shift_val
            else:
                return ts
        elif np.size(ts) > 1:
            ts = np.copy(ts)
            ts[np.where(ts >= shift_t)] += shift_val
            return np.asarray(ts)
        else:
            print "unknown type supplied"

    def phase_of_time(times):
        return (times * 2 * np.pi / pmodel.T) % (2 * np.pi)

    cx.plot(
        np.asarray(tphases) / 23.7 * 24. - 0.25 * 24., np.sin(contphases), 'l')
    cx.plot(
        np.asarray(tphases) / 23.7 * 24. - 0.25 * 24.,
        np.sin(phase_of_time(shift_time(tphases))), 'k--')
    cx.set_xlim([12, 72])
    cx.set_xticks([24, 36, 48, 60])
    cx.set_xticklabels([])
    cx.set_ylim([-1., 1.45])
    cx.set_ylabel('sin($\phi$)')

    dx.step(control_inputs[1:, 0] / 23.7 * 24 - .25 * 24,
            -control_inputs[:-1, 1],
            '0.7',
            label='Control Input')
    dx.set_xlim([12, 72])
    dx.set_ylim([0, 0.11])
    dx.set_xticks([12, 24, 36, 48, 60, 72])
    dx.set_yticks([0, 0.05, 0.10])
    dx.set_xticklabels([''])
    dx.set_ylabel('u')
    for tl in dx.get_yticklabels():
        tl.set_color('0.7')

    dx2 = dx.twinx()
    dx2.plot(
        np.asarray(tphases) / 23.7 * 24. - 0.25 * 24.,
        -pmodel.pPRC_interp(pmodel._phi_to_t(np.asarray(contphases)))[:, 15],
        'f')
    dx2.set_xticks([12, 24, 36, 48, 60, 72])
    dx2.set_xlim([12, 72])
    plo.format_4pi_axis(dx2, x=False, y=True)
    for tl in dx2.get_yticklabels():
        tl.set_color('f')

    ex.step(time_steps[1:-pred_win + 1] / 23.7 * 24 - .25 * 24,
            errors[:],
            'k',
            label='Phase Error')
    ex.set_xlim([12, 72])
    ex.set_xticks([12, 24, 36, 48, 60, 72])
    ex.set_yticks([0, 0.5, 1.0, 1.5])
    ex.set_ylabel('Error (rad$^2$)')
    ex.set_xlabel('Time (h)')