Python_01d
This page covers are the absolute basics of line plotting using Matplotlib
Simple plotting
This is the simplest example of plotting a line on a graph - combined with adding another line to the same graph - and plotting a third line on a separate axis
We start by importing matplotlib.pyplot which I use because it makes simple plotting in Python feel familiar to Matlab users
We also import numpy to do the maths
# use libraries for maths functions
# and Matlab style plotting
import numpy as np
import matplotlib.pyplot as plt
Next we generate three simple sine wave signals of different frequencies and offset the second one on the Y axis. We call these s1 and s2 and s3
# three example sinewaves
t = np.arange(0.0, 5.0, 0.01)
s1 = np.cos(2*np.pi*t)
s2 = np.sin(4*np.pi*t)+2
s3 = np.sin(8*np.pi*t)
Finally we plot two signals on the same axis and the third on a separate axis.
# start new figure and plot both lines on it
plt.figure()
plt.plot(s1)
plt.plot(s2)
plt.show
#start new figure and plot third line on it
plt.figure()
plt.plot(s3)
plt.show