from scipy import arange
import matplotlib.pyplot as plt
import DiscretizedMaps as dm
import numpy as np
import sys

# This program simply displays a plot of a discretized map, along with the continuous map it is approximating

Ncont=800 # This is the number of grid points which we use to plot the 'continuous' map

# The program arguments are assigned to the proper variables
# mapkey is a string which determines which map to use
mapkey,r,N=sys.argv[1:]
r,N=float(r),float(N)

# here the map strings are associated with their  DiscretizedMaps object.
maps = {'logistic':dm.Logistic, 'tent':dm.Tent, 'logisticrand':dm.LogisticRand, 'tentrand':dm.TentRand}
# the map is assigned using the user input mapkey string
map=maps[mapkey]

# arrays of x values and function values are constructed for both the discrete and continuous maps
xdisc=arange(0,1,1/float(N))
fdisc=arange(0,1,1/float(N))
xcont=arange(0,1,1/float(Ncont))
fcont=arange(0,1,1/float(Ncont))
for i in xrange(len(xdisc)):
	fdisc[i]=map.iterate(xdisc[i],r,N,1)
for i in xrange(len(xcont)):
	fcont[i]=map.iterate(xcont[i],r,Ncont,1)

# The maps are plotted and labeled
plt.plot(xdisc,fdisc,'.',color=(0.,0.,1.))
plt.plot(xcont,fcont,color=(1.,0.,0.))
plt.plot(xdisc,np.array(xdisc)*0,'s',color=(0.,1.,0.))
plt.plot(np.array(xdisc)*0,xdisc,'s',color=(0.,1.,0.))
plt.title(map.titlestring + ' N=' + `N`)
plt.xlabel('x')
plt.ylabel('f(x)')
plt.show()
