Main.Subplots History

Hide minor edits - Show changes to markup

May 03, 2010, at 07:38 AM MST by 71.196.160.210 -
Added lines 1-37:

(:source lang=python:)

""" creating multiple subplots adapted from: http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/subplot_demo.py """

import numpy as np import matplotlib.pyplot as plt

def f(t):

    s1 = np.cos(2*np.pi*t)
    e1 = np.exp(-t)
    return np.multiply(s1,e1)

t1 = np.arange(0.0, 5.0, 0.1) t2 = np.arange(0.0, 5.0, 0.02) t3 = np.arange(0.0, 2.0, 0.01)

fig = plt.figure() ax = fig.add_subplot(211)

l = ax.plot(t1, f(t1), 'bo', t2, f(t2), 'k--', markerfacecolor='green') ax.grid(True) ax.set_title('A tale of 2 subplots') ax.set_ylabel('Damped oscillation')

ax = fig.add_subplot(212) ax.plot(t3, np.cos(2*np.pi*t3), 'r.') ax.grid(True) ax.set_xlabel('time (s)') ax.set_ylabel('Undamped')

fig.show()

(:sourceend:)