#import matplotlib
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
# Package all mpl plotting commands inside one function
def plot_mpl_fig():
# Make two time arrays
t1 = np.arange(0.0, 2.0, 0.1)
t2 = np.arange(0.0, 2.0, 0.01)
# N.B. .plot() returns a list of lines.
# The "l1, = plot" usage extracts the first element of the list
# into l1 using tuple unpacking.
# So, l1 is a Line2D instance, not a sequence of lines
l1, = plt.plot(t2, np.exp(-t2), label='decaying exp.')
l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--go',
t1, np.log(1 + t1), '.')
l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 'rs-.')
# Add axis labels and title
plt.xlabel('time')
plt.ylabel('volts')
plt.title('Damped oscillation')
return (l1, l2, l3, l4) # return line objects (for legend, later)
# Plot it!
plot_mpl_fig()
#assigning current matplotlib object
#gcf stands for get current figure.
mpl_fig1 = plt.gcf()