In [10]:
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from matplotlib2tikz import save as tikz_save
In [11]:
# colors = ['b', 'r', 'g', 'c', 'm', 'k']
# Have a look at the colormaps here and decide which one you'd like:
# http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html
# colormap = plt.cm.winter
# colormap = plt.cm.autumn
# colormap = plt.cm.summer
# colormap = plt.cm.ocean
colormap = plt.cm.gist_heat
N_COLORS = 10
colors = [colormap(i) for i in np.linspace(0, 0.7, N_COLORS)]
# # OR
# import matplotlib as mpl # in python
# # custom colormap generated with http://colormap.org/
# C = np.array([[255,124,0],[254,123,1],[253,123,1],[252,123,2],[251,123,2],[250,123,3],[249,122,3],[248,122,4],[246,122,4],[245,122,5],[244,122,5],[243,122,6],[242,121,7],[241,121,7],[240,121,8],[239,121,8],[238,121,9],[237,120,9],[236,120,10],[235,120,10],[234,120,11],[233,120,11],[232,119,12],[230,119,13],[229,119,13],[228,119,14],[227,119,14],[226,118,15],[225,118,15],[224,118,16],[223,118,16],[222,118,17],[221,117,17],[220,117,18],[219,117,19],[218,117,19],[217,117,20],[216,116,20],[214,116,21],[213,116,21],[212,116,22],[211,116,22],[210,115,23],[209,115,23],[208,115,24],[207,115,25],[206,115,25],[205,115,26],[204,114,26],[203,114,27],[202,114,27],[201,114,28],[200,114,28],[198,113,29],[197,113,29],[196,113,30],[195,113,31],[194,113,31],[193,112,32],[192,112,32],[191,112,33],[190,112,33],[189,112,34],[188,111,34],[187,111,35],[185,112,36],[184,112,38],[183,113,39],[181,113,40],[180,113,42],[178,114,43],[177,114,44],[176,115,46],[174,115,47],[173,115,48],[171,116,50],[170,116,51],[169,117,52],[167,117,54],[166,117,55],[165,118,56],[163,118,58],[162,119,59],[160,119,60],[159,119,62],[158,120,63],[156,120,64],[155,121,66],[153,121,67],[152,121,68],[151,122,70],[149,122,71],[148,123,72],[147,123,74],[145,123,75],[144,124,76],[142,124,78],[141,125,79],[140,125,80],[138,125,82],[137,126,83],[136,126,84],[134,127,86],[133,127,87],[131,127,88],[130,128,90],[129,128,91],[127,129,92],[126,129,94],[124,129,95],[123,130,96],[122,130,98],[120,131,99],[119,131,100],[118,131,102],[116,132,103],[115,132,104],[113,133,106],[112,133,107],[111,133,108],[109,134,110],[108,134,111],[107,135,112],[105,135,114],[104,135,115],[102,136,116],[101,136,118],[100,137,119],[98,137,120],[97,137,121],[96,137,122],[95,137,123],[94,138,124],[94,138,125],[93,138,126],[92,138,127],[91,138,128],[90,138,129],[89,139,130],[88,139,131],[87,139,132],[86,139,133],[85,139,134],[84,139,135],[83,140,136],[82,140,137],[81,140,137],[80,140,138],[79,140,139],[78,140,140],[77,141,141],[76,141,142],[75,141,143],[74,141,144],[73,141,145],[72,141,146],[71,142,147],[70,142,148],[69,142,149],[68,142,150],[67,142,151],[66,142,152],[65,143,153],[64,143,154],[63,143,155],[62,143,156],[61,143,157],[60,143,158],[59,144,159],[58,144,160],[57,144,160],[56,144,161],[55,144,162],[54,144,163],[53,145,164],[52,145,165],[51,145,166],[50,145,167],[49,145,168],[48,146,169],[47,146,170],[46,146,171],[45,146,172],[44,146,173],[43,146,174],[42,147,175],[41,147,176],[40,147,177],[40,147,178],[39,147,179],[38,147,180],[37,148,181],[36,147,182],[35,147,182],[35,146,183],[34,146,184],[34,145,185],[33,144,186],[32,144,187],[32,143,188],[31,143,189],[31,142,190],[30,142,191],[30,141,192],[29,140,192],[28,140,193],[28,139,194],[27,139,195],[27,138,196],[26,138,197],[26,137,198],[25,137,199],[24,136,200],[24,135,201],[23,135,202],[23,134,202],[22,134,203],[22,133,204],[21,133,205],[21,132,206],[20,132,207],[19,131,208],[19,130,209],[18,130,210],[18,129,211],[17,129,212],[17,128,212],[16,128,213],[15,127,214],[15,127,215],[14,126,216],[14,125,217],[13,125,218],[13,124,219],[12,124,220],[11,123,221],[11,123,222],[10,122,222],[10,122,223],[9,121,224],[9,120,225],[8,120,226],[7,119,227],[7,119,228],[6,118,229],[6,118,230],[5,117,231],[5,117,232],[4,116,232],[3,115,233],[3,115,234],[2,114,235],[2,114,236],[1,113,237],[1,113,238],[0,112,239]])
# colormap = mpl.colors.ListedColormap(C/255)
In [25]:
%matplotlib inline
from __future__ import division
import numpy as np
from numpy.polynomial.polynomial import polyroots
# define regimes (alpha, beta_1, beta_2, epsilon) (delta_1 = delta_2 = 0 always)
regimes = {'Linear': (-5.0, 0, 0), # linear
'Critical': (0, -25.0, 0), # critical
'Sub-Critical': (-5.0, -5.0, 0), # sub-critical
'Super-Critical': (5, -15.0, 0), # super-critical (limit cycle)
# 'Limit-Cycle': (0, -1.0, -1.0), # limit-cycle
'Sub-Critical Double Limit-Cycle': (-5.0, 10.0, -2.0), # double limit-cycle
'Super-Critical Double Limit-Cycle': (-5.0, 15.0, -2.0), # double limit-cycle
}
# F = np.arange(0, 2, 0.2)
# F = [1]
F = [0, 1, 2]
epsilon = 1.0
colors = [colormap(i) for i in np.linspace(0, 0.7, len(F))]
plot_roots = True
for regime in regimes:
alpha, beta1, beta2 = regimes[regime]
r = np.arange(0, 1/np.sqrt(epsilon), 0.01)
rdot = np.add.outer(alpha * r + beta1 * r**3 + ((epsilon* beta2 * r**5)/(1 - epsilon * r**2)), F)
plt.figure(figsize=(6,3))
ax = plt.gca()
ax.set_color_cycle(colors)
plt.plot(r, rdot, zorder=0, linewidth=2)
# plt.plot(r, rdot, zorder=0, color=PLOT_COLOR, linewidth=3)
# assymptote
# plt.vlines(x=1/np.sqrt(epsilon), ymin=-1, ymax=2, color='r', linestyle=':')
plt.ylim(-5,5)
ax.axhline(y=0,xmin=min(r),xmax=max(r),c="k",zorder=5, alpha=0.5)
# plt.grid(True)
# plt.title(r'{}: $\alpha={:.3g}, \; \beta_1={:.3g}, \; \beta_2={:.3g}, \; \varepsilon={:.3g}$'.format(regime, alpha, beta1, beta2, epsilon))
plt.title(r'$\alpha={:.3g}, \; \beta_1={:.3g}, \; \beta_2={:.3g}$'.format(alpha, beta1, beta2), y=1.0)
plt.xlabel(r'$r$')
plt.ylabel(r'$\dot{r}$', labelpad=-10)
if plot_roots:
# find roots
roots = [None] * len(F)
for i in xrange(len(F)):
# r = np.roots([epsilon*(beta2-beta1), 0, beta1-epsilon*alpha, -epsilon*F[i], alpha, F[i]])
r = polyroots([F[i], alpha, -epsilon*F[i], beta1-epsilon*alpha, 0, epsilon*(beta2-beta1)])
r = np.real(r[np.abs(np.imag(r)) < 1e-20])
r = r[(r>=0) & (r < 1/np.sqrt(epsilon))]
roots[i] = r
# print roots
# plt.gca().set_color_cycle(colors)
for r in roots:
plt.plot(r, np.zeros_like(r), 'o', markersize=4, zorder=10)
# plt.plot(r, np.zeros_like(r), 'o', markersize=4, zorder=10, color='white')
# sanitizedName = regime.replace(' ','').replace('-','')
# tikz_save('/Users/jorgeh/Documents/CCRMA/research/ismir2015/frameworkPaper/figs/regimes/{}.tikz'.format(sanitizedName), figureheight='1.5cm', figurewidth='3cm')
In [ ]: