def sine_timeplot_fig(mu_vals = [-1e-3, -0.1, -0.3, -0.40]):
    # set up the model parameters for this figure
    # mu = -0.2
    alpha = 0.23333
    k = 1
    n_phis = np.linspace(0, 2*math.pi, 4*20+1)
    dx = 1e-4
    dy = 0.
    mag = math.sqrt(dx**2 + dy**2)
    phasescale = 4 / (2 * math.pi) # convert from (0,2 \pi) to (0,4)

    # create a new figure
    fig = plt.figure(figsize=(6,6))

    width = 1./len(mu_vals)
    padding = 0.2*width

    for i in range(len(mu_vals)):
        mu = mu_vals[i]

        axes = plt.axes((2*padding, 1-(i+1) * width+padding,
            1 - width - 2*padding, width - 1.5*padding))

        # draw the trajectory components vs. time
        T, y0, error = iris.sine_limit_cycle(mu, alpha, k)
        ts = np.linspace(0, 3*T, 1000);
        vals = integrate.odeint(iris.sine_system,
                [0, -y0],
                ts,
                args=(mu, alpha, k))
        axes.plot(ts, vals[:,1], '-', color='0.8', lw=2)
        axes.plot(ts, vals[:,0], 'k-', lw=2)

        axes.set_xlim(0, 3*T)

        # make the y-axis symmetric around zero
        #ymaxabs = np.max(np.abs(axes.get_ylim()))
        ymaxabs = 0.6*math.pi
        axes.set_ylim(-ymaxabs, ymaxabs)

        # draw the phase plot for reference
        axes = plt.axes((1-width+padding, 1-(i+1) * width + padding,
            width - 1.5 * padding, width - 1.5 * padding))
        iris.draw_fancy_sine_system(axes, mu, alpha, k, scale=3.)

        # center the plot and clean up the scale bars
        border = 0.2
        axes.set_xlim(-math.pi/2-border, math.pi/2+border)
        axes.set_ylim(-math.pi/2-border, math.pi/2+border)
        axes.set_xticks([])
        axes.set_yticks([])
        axes.set_frame_on(False)

    return fig
def sine_prc_fig(mu_vals = [-1e-3, -0.1, -0.3, -0.40]):
    # set up the model parameters for this figure
    # mu = -0.2
    alpha = 0.23333
    k = 1
    n_phis = np.linspace(0, 2*math.pi, 4*20+1)
    dx = 1e-4
    dy = 0.
    mag = math.sqrt(dx**2 + dy**2)
    phasescale = 4 / (2 * math.pi) # convert from (0,2 \pi) to (0,4)

    # create a new figure
    fig = plt.figure(figsize=(6,6))

    width = 1./len(mu_vals)
    padding = 0.2*width

    for i in range(len(mu_vals)):
        mu = mu_vals[i]

        axes = plt.axes((2*padding, 1-(i+1) * width+padding,
            1 - width - 2*padding, width - 1.5*padding))

        # draw the orthogonal prc found numerically
        T, y0, error = iris.sine_limit_cycle(mu, alpha, k)
        n_prc_o = np.array([
            iris.sine_phase_reset(phi, dx=-dy, dy=dx, mu=mu, alpha=alpha, k=k,
                y0=y0, T=T,
                steps_per_cycle=100000)
            for phi in n_phis
            ])
        orthogonal_color = '0.8'
        axes.plot(n_phis, n_prc_o/mag*phasescale, '--', markersize=3,
                color=orthogonal_color)
        axes.plot(n_phis, n_prc_o/mag*phasescale, 'bo', markersize=3,
                color=orthogonal_color, markeredgecolor=orthogonal_color)
        axes.set_xlim(0, 2*math.pi)

        # draw the prc found numerically
        T, y0, error = iris.sine_limit_cycle(mu, alpha, k)
        n_prc = np.array([
            iris.sine_phase_reset(phi, dx=dx, dy=dy, mu=mu, alpha=alpha, k=k,
                y0=y0, T=T,
                steps_per_cycle=100000)
            for phi in n_phis
            ])
        axes.plot(n_phis, n_prc/mag*phasescale, '--k', markersize=3)
        axes.plot(n_phis, n_prc/mag*phasescale, 'bo', markersize=3)
        axes.set_xlim(0, 2*math.pi)
        plt.xticks(np.arange(5.)*math.pi/2,
                #['$0$', '$\\pi/2$', '$\\pi$',
                #    '$3\\pi/2$', '$2\\pi$'])
                # phase rescaled from 0 to 4 to match analysis
                ['$0$', '$1$', '$2$', '$3$', '$4$'])
        # make the y-axis symmetric around zero
        ymaxabs = np.max(np.abs(axes.get_ylim()))
        axes.set_ylim(-ymaxabs, ymaxabs)

        # draw the phase plot for reference
        axes = plt.axes((1-width+padding, 1-(i+1) * width + padding,
            width - 1.5 * padding, width - 1.5 * padding))
        iris.draw_fancy_sine_system(axes, mu, alpha, k, scale=3.)

        # center the plot and clean up the scale bars
        border = 0.2
        axes.set_xlim(-math.pi/2-border, math.pi/2+border)
        axes.set_ylim(-math.pi/2-border, math.pi/2+border)
        axes.set_xticks([])
        axes.set_yticks([])
        axes.set_frame_on(False)

    return fig