Matplotlib is a very powerful tool for making graphs in Python. No graphing utility would be complete without allowing customization of each line on a graph. As is common with Matplotlib and Python, modifying how your lines look is both easy and powerful.
When using the plot function, it is as simple as passing in a two character string which specifies what kind of line it will be (or if it should just be markers), and what color. Here is an example of a graph which uses red circles as markers with no line.
1 |
plot(x_series, y_series, 'ro')
|
The first character in the string represents the color; the second represents the shape of marker or style of line used. The following tables show a mapping of allowable colors and characters.
|
|
Here is another example, this time showing a full python script.
1 2 3 4 5 6 7 8 9 10 11 12 |
#set up matplotlib and a new figure import matplotlib.pyplot as plt plt.figure() #create data x_series = [0,1,2,3,4,5] y_series_1 = [x**2 for x in x_series] y_series_2 = [x**3 for x in x_series] plt.plot(x_series, y_series_1, 'r-') plt.plot(x_series, y_series_2, 'c--') plt.savefig("example.png") |





