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
def sine_fig(mu = -0.1): alpha = 0.23333 k = 1 # create a new figure fig = plt.figure(figsize=(3.5,3.5)) #axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) #axes = fig.add_axes([0.1, 0.1, 0.89, 0.89]) axes = fig.add_axes([0.07, 0.07, 0.92, 0.92]) # draw the vector field X, Y = np.meshgrid( np.linspace(-math.pi, math.pi, 6*4+1)+ math.pi/(6*4), np.linspace(-math.pi, math.pi, 6*4+1)+ math.pi/(6*4) ) (U,V) = iris.sine_system(np.asarray([X, Y]), 0., mu, alpha, k) axes.quiver(X, Y, U, V) # draw the x nullclines ys = xs = np.linspace(-math.pi, math.pi, 4*200) # Each x nullcline exists within a diagonal band; # calculate the band's height from the intersection of the nullclines # when mu = 0. h1 = 2 * math.asin(2*alpha) + math.pi h2 = math.pi - 2 * math.asin(2*alpha) nullx1 = np.array([ optimize.brentq( lambda y : iris.sine_system(np.asarray([x,y]), 0., mu, alpha, k)[0], x + h1/2, x - h1/2 ) for x in xs ]) axes.plot(xs, nullx1, 'k') axes.plot(xs, nullx1 - 2*math.pi, 'k') axes.plot(xs, nullx1 + 2*math.pi, 'k') nullx2 = np.array([ optimize.brentq( lambda y : iris.sine_system(np.asarray([x,y]), 0., mu, alpha, k)[0], x + math.pi + h2/2, x + math.pi - h2/2 ) for x in xs ]) axes.plot(xs, nullx2, 'k') axes.plot(xs, nullx2 - 2*math.pi, 'k') axes.plot(xs, nullx2 + 2*math.pi, 'k') # plot the y nullclines nully1 = np.array([ optimize.brentq( lambda x : iris.sine_system(np.asarray([x,y]), 0., mu, alpha, k)[1], -y + h1/2, -y - h1/2 ) for y in ys ]) axes.plot(nully1, ys, 'k', dashes=(2,1)) axes.plot(nully1 - 2*math.pi, ys, 'k', dashes=(2,1)) axes.plot(nully1 + 2*math.pi, ys, 'k', dashes=(2,1)) nully2 = np.array([ optimize.brentq( lambda x : iris.sine_system(np.asarray([x,y]), 0., mu, alpha, k)[1], -y + math.pi + h2/2, -y + math.pi - h2/2 ) for y in ys ]) axes.plot(nully2, ys, 'k', dashes=(2,1)) axes.plot(nully2 - 2*math.pi, ys, 'k', dashes=(2,1)) axes.plot(nully2 + 2*math.pi, ys, 'k', dashes=(2,1)) # draw the limit cycle and limit points iris.draw_fancy_sine_system(axes, mu, alpha, k, scale=1.) # add a trajectory x0 = [0, 0.1] vals = integrate.odeint(iris.sine_system, x0, np.linspace(0, 200, 20000), args=(mu, alpha, k)) axes.plot(vals[:,0], vals[:,1], 'b', lw=1) # center the plot and clean up the scale bars border = 0.0 axes.set_xlim(-math.pi/2-border, math.pi/2+border) axes.set_ylim(-math.pi/2-border, math.pi/2+border) plt.xticks(np.linspace(-2, 2, 5)*math.pi/2, [r'$-\pi$', r'$-\frac{\pi}{2}$', '$0$', r'$\frac{\pi}{2}$', r'$\pi$']) #[r'$-\pi$', r'$-\pi/2$', '$0$', r'$\pi/2$', r'$\pi$']) plt.yticks(np.linspace(-2, 2, 5)*math.pi/2, [r'$-\pi$', r'$-\frac{\pi}{2}$', '$0$', r'$\frac{\pi}{2}$', r'$\pi$']) return fig