# simple_plot_2.py: Plotting defined functions, making multiple
#    subplots, and using line styles and various data tokens.

# Import modules
# for the numerical functions
from numpy import *
from pylab import * # plotting

# Define a sinusoidal function with exponential deacy
def f(t):
	s1 = cos(2*pi*t)
	e1 = exp(-t)
	return multiply(s1,e1)

# Setup two time arrays
#
t1 = arange(0.0,5.0,0.1)
t2 = arange(0.0,5.0,0.02)

# Setup to produce two plots in the same window
#
# Identity the overall plot (aka 'figure')
figure(1)
# Now set up the first graph
subplot(211)
# Give it a name, so we can identity it when displayed
title('Plot with blue dots and black line')
# Now plot:
# 	First, plot (t1,f(t1)) as a series of blue ('b') circles ('o')
# 	Then, through these plot (t2,f(t2)) using a finer set (t2) of points
#		connected by a black ('k') line
plot( t1, f(t1), 'bo', t2, f(t2), 'k' )

# Here's the second graphic; we give it a different identifier
#   Note that matplotlib defaults to laying out the two plots how it sees fit.
#	This can be controlled, by over-riding the default behavior.
subplot(212)
# Again, we add an identifying heading
title('Plot with red dashed lines')
# And plot another function with a red ('r') dashed line ('--')
plot( t2, cos(2*pi*t2), 'r--')

# We can save the graphics as a png bitmap-formatted figure to a file
#	The png-format type is the default.
#
# Use this command to do it
#savefig('simple_plot_2', dpi=600)
#
# If a vector-graphics format is desired, you can save to PostScript using
#savefig('simple_plot_2.ps', dpi=600)
#  Note that the desired output format is specified by
#		the .ps file extension.

# Display plot in window
show()
