def iris_fig(a, border=1., label_theta0=True):
    # set up the model parameters for this figure
    l_cw = -default_lambda
    l_ccw = 1
    X = Y = 1.

    # create a new figure
    fig = plt.figure(figsize=(5,5))
    axes = fig.add_axes([0., 0., 1., 1.])

    iris.draw_fancy_iris(axes, a, l_ccw, l_cw, X, Y)

    # add an arrow indicating theta = 0
    if label_theta0:
        r0s = iris.iris_fixedpoint(a, l_ccw, l_cw, X, Y, guess=1e-6*X)
        if r0s != None:
            axes.annotate(r'$\theta = 0$',
                xy=(a/2, -X + r0s - a/2), xycoords='data',
                xytext=(15,15), textcoords='offset points',
                arrowprops=dict(arrowstyle='->',
                    connectionstyle='angle,angleA=180,angleB=240,rad=10')
                )
        r0u = iris.iris_fixedpoint(a, l_ccw, l_cw, X, Y, guess=1*X)
        if a != 0 and r0u != None:
            axes.annotate(r'',
                xy=(-X + r0u - a/2, -a/2), xycoords='data',
                xytext=(-15,15), textcoords='offset points',
                arrowprops=dict(arrowstyle='->', color='r',
                    connectionstyle='angle,angleA=-180,angleB=-45,rad=0')
                )
        if a != 0 and r0u != None:
            x0 = [-a/2, a/2 + Y - (0.9*r0u + 0.1*r0s)]
        elif a == 0:
            x0 = [-a/2, a/2 + Y - 0.9]
        else:
            x0 = [-a/2, 0.9*Y]
        axes.annotate(r'',
            xy=x0, xycoords='data',
            xytext=x0 + np.r_[-1.0e-3, 0.5e-3], textcoords='data',
            arrowprops=dict(arrowstyle='->', color='b',
                connectionstyle='arc3,rad=0')
            )

    # center the plot and clean up the scale bars
    axes.set_xlim(-2*X-border, 2*X+border)
    axes.set_ylim(-2*Y-border, 2*Y+border)
    axes.set_xticks([])
    axes.set_yticks([])
    axes.set_frame_on(False)
    return fig
def iris_timeplot_fig(a_vals = sample_a_vals, border = 0.3):
    # set up the model parameters for this figure
    l_cw = -default_lambda
    l_ccw = 1
    X = Y = 1.
    n_phis = np.linspace(0, 2*math.pi, 20*4 + 1)
    a_phis = np.linspace(0, 2*math.pi, 100*4 + 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(a_vals)
    padding = 0.2*width

    for i in range(len(a_vals)):
        a = a_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
        r0 = iris.iris_fixedpoint(a, l_ccw, l_cw, X, Y, guess=1e-6*X)
        T = 4 * iris.dwell_time(r0, l_ccw, l_cw, X, Y)
        ts = np.linspace(0, 3*T, 1000);
        vals = integrate.odeint(iris.iris,
                [-a/2, -a/2 - Y + r0],
                ts,
                args=(a, l_ccw, l_cw, X, Y))
        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 = 1.2
        axes.set_ylim(-ymaxabs, ymaxabs)


        # draw the phase plot for reference
        axes = plt.axes((1-width, 1-(i+1) * width, width, width))
        iris.draw_fancy_iris(axes, a, l_ccw, l_cw, X, Y,
                scale=3.0, x0=np.nan)

        # center the plot and clean up the scale bars
        axes.set_xlim(-2*X-border, 2*X+border)
        axes.set_ylim(-2*Y-border, 2*Y+border)
        axes.set_xticks([])
        axes.set_yticks([])
        axes.set_frame_on(False)

    return fig
def nomenclature_fig():
    # set up the model parameters for this figure
    a = 0.1
    l_cw = -default_lambda
    l_ccw = 1
    X = Y = 1.
    def saddlefunc(y,t):
        return [y[0]*l_cw, y[1]*l_ccw]

    # create a new figure
    fig = plt.figure(figsize=(6,6))
    axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])

    # draw the axes
    iris.draw_saddle_neighborhood(axes, -X, -Y, 2*X, 2*Y, True, False,
            scale=0.7)

    axes.text(-1.05, 0.5, '$Y$',
            horizontalalignment = 'right', verticalalignment='center')
    axes.text(0.5, -1.05, '$X$',
            horizontalalignment = 'center', verticalalignment='top')

    # draw the stable limit cycle
    r0 = iris.iris_fixedpoint(a, l_ccw, l_cw, X, Y, guess=1e-6*X)
    vals = integrate.odeint(saddlefunc, [X,r0],
            np.linspace(0, iris.dwell_time(r0, l_ccw, l_cw, X, Y), 1000),
            )#args=(a, l_ccw, l_cw, X, Y))
    axes.plot(vals[:,0], vals[:,1], 'k', lw=2)

    # draw a sample trajectory
    x0 = [X, r0*2]
    vals = integrate.odeint(saddlefunc, x0,
            np.linspace(0, iris.dwell_time(x0[1], l_ccw, l_cw, X, Y), 1000),
            )#args=(a, l_ccw, l_cw, X, Y))
    axes.plot(vals[:,0], vals[:,1], 'b', lw=1)

    # center the plot and clean up the scale bars
    axes.set_xlim(-X, X)
    axes.set_ylim(-Y, Y)
    axes.set_xticks([])
    axes.set_yticks([])
    axes.set_frame_on(False)
    return fig