import pylab as pl
import numpy as np

# set frequency, amplitude and the independent variable array
omega = 2*np.pi; V0 = 1
t = np.linspace(-2.,2.,500)

# set the increment in deltaphi
deltaphi_step = -.1*np.pi

# define the function
def func(x,deltaphi):
    return (V0*np.cos(omega*x+deltaphi))

# set the initial value for deltaphi
deltaphi = 0

# prepare the "reference" waveform
V_0 = func(t,deltaphi)


# cycle to prepare and display the pairs of functions to be displayed
for counter in range (1,7):         # start a for cycle
    V = func(t,deltaphi)            # compute the function
    pl.subplot(3, 2, counter)          # call the subplot (indexed by counter)
    pl.rc('font',size=9)
    pl.plot(t,V_0,color='blue')     # plot the reference as a function of t
    pl.plot(t,V,color='red')        # plot the dephased waveform as a function of t
    pl.xticks([-2,-1,0,1,2])
    pl.yticks([-.5,0,.5])
    pl.grid()
    pl.text(0.7,.6,('$\Delta \phi$ = %1.1f' %(deltaphi/(np.pi/2)) +' $\pi$/2'),fontsize=9)
    if counter == 5 or counter == 6:    # set axis name when needed
        pl.xlabel('$t$  [T]',fontsize = 12)
    if counter == 1 or counter == 3 or counter  == 5:
        pl.ylabel('CH2 [arb.un.]',fontsize=12)
    deltaphi+=deltaphi_step
    
pl.savefig('D:/stash/dida14_15/lab2_14_15/sfasamento/fig1.pdf')
pl.show()

# the following lines are needed to prepare the parametric plots

# set the initial value for deltaphi
deltaphi = 0

# prepare the "reference" waveform
V_0 = func(t,deltaphi)

for counter in range (1,7):         # start a for cycle
    V = func(t,deltaphi)            # compute the function
    pl.subplot(3, 2, counter)          # call the subplot (indexed by counter)
    pl.rc('font',size=9)
    pl.xlim(-1.1,1.1);pl.ylim(-1.1,1.1)
    pl.plot(V_0,V,color='black')    # plot the dephased waveform as a function of reference
    pl.xticks([-1,-.5,0,.5,1])
    pl.yticks([-1,-.5,0,.5,1])
    pl.grid()
    pl.text(0.35,.6,('$\Delta \phi$ = %1.1f' %(deltaphi/(np.pi/2)) +' $\pi$/2'),fontsize=9)
    if counter == 5 or counter == 6:    # set axis name when needed
        pl.xlabel('$t$  [T]',fontsize = 12)
    if counter == 1 or counter == 3 or counter  == 5:
        pl.ylabel('CH2 [arb.un.]',fontsize=12)
    deltaphi+=deltaphi_step
    
pl.savefig('D:/stash/dida14_15/lab2_14_15/sfasamento/fig2.pdf')
pl.show()
        
