from matplotlib import pyplot as plt import numpy as np plt.figure() # Make a new figure window plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.clf() # this clears the existing figure plt.plot([1,2,3,4], [1,4,9,16]) plt.clf() plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) t = np.arange(0., 5., 0.2) plt.clf() plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.plot(t, t+60, 'co-') plt.clf() x = np.linspace(0, 4*np.pi, 100) plt.plot(x, np.sin(x), 'g') plt.xlim(0, 4*np.pi) plt.ylim(-1.1, 1.1) x = np.arange(0, 10, 0.25) y = np.sin(x) plt.clf() plt.plot(x, y, linewidth=4.0) plt.clf() line, = plt.plot(x, y, '-') line.set_color('m') # change color plt.draw() x = [1, 2, 3, 4] y = [3, 2, 3, 1] plt.clf() plt.plot(x,y,marker='*',linestyle='--',color='b',linewidth=10,markerfacecolor='r',markeredgecolor='b',markeredgewidth=5,markersize=40) plt.xlim(0, 5) plt.ylim(0, 4) def f(t): """Python function to calculate a decaying sinusoid""" val = np.exp(-t) * np.cos(2*np.pi*t) return val t1 = np.arange(0.0, 5.0, 0.1) t2 = np.arange(0.0, 5.0, 0.02) plt.figure(1) # Make the first figure plt.clf() plt.subplot(211) # 2 rows, 1 column, plot 1 plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') plt.title('FIGURE 1') plt.text(2, 0.8, 'AXES 211') plt.subplot(212) # 2 rows, 1 column, plot 2 plt.plot(t2, np.cos(2*np.pi*t2), 'r--') plt.text(2, 0.8, 'AXES 212') plt.figure(2) # Make a second figure plt.clf() plt.plot(t2, f(t2), '*') plt.grid() plt.title('FIGURE 2') plt.text(2, 0.8, 'AXES 111') plt.figure(1) # Select the existing first figure plt.subplot(212) # Select the existing subplot 212 plt.plot(t2, np.cos(np.pi*t2), 'g--') # Add a plot to the axes plt.text(2, -0.8, 'Back to AXES 212') plt.close('all') # close all previous plots plt.axes([0.6,0.1,0.30,0.6]) # left, bottom, width, height in figure fractions plt.axes([0.2,0.4,0.60,0.5])