# only necessary for iPython Notebook to place the graph in the HTML page, ignore
%matplotlib inline
First, we need to import two modules, Matplotlib's PyPlot and Numpy.
import numpy as np
import matplotlib.pyplot as plt
Now, let's create a set of random data to plot using Numpy's Random. Within Random, there is a basic random function, numpy.random.random.
data = np.random.random(100) # 100 is the number of random points we will be plotting
The data looks something like this:
print(data)
Next, let's plot the data in a plain line graph
plt.plot(data)
Now, let's make the plot a little more customized.
plt.plot(data, color='black', linestyle='dashed', marker='o',
markerfacecolor='red', markersize=6)
Notice you can easily specify the color of the line and markers, the style of the line and markers (even hiding either one), and customize any other aspect of the line plot not shown here. Python allows you to choose colors in a number of ways, I recommend using the names of HTML colors as strings. I use this link: http://www.w3schools.com/html/html_colornames.asp as a reference for many of the availabe colors.
Let's just go back to a simpler plot:
plt.plot(data,color='red',linewidth=2)
And now, let's add labels, a legend, and a title.
plt.plot(data,color='red',linewidth=2,label='Data')
plt.title('Random Data Plot')
plt.xlabel('Datapoint #')
plt.ylabel('Random Value')
plt.legend()
plt.show() # use this command to show the plot in an X-Window
plt.savefig('filename.png') # use this command to save the image as a .png or .pdf or .svg (depending on what the filename is)
That's all there is to making a basic line plot. For more information on Matplotlib, including all of the plot types and the ways you can customize the plots, go to http://www.matplotlib.org.