A complete example
Let's now group together all that we've seen so far and create a complete example as follows:
In [1]: import matplotlib.pyplot as plt In [2]: import numpy as np In [3]: x = np.arange(1, 5) In [4]: plt.plot(x, x*1.5, label='Normal') Out[4]: [<matplotlib.lines.Line2D object at 0x2ab5f50>] In [5]: plt.plot(x, x*3.0, label='Fast') Out[5]: [<matplotlib.lines.Line2D object at 0x2ac5210>] In [6]: plt.plot(x, x/3.0, label='Slow') Out[6]: [<matplotlib.lines.Line2D object at 0x2ac5650>] In [7]: plt.grid(True) In [8]: plt.title('Sample Growth of a Measure') Out[8]: <matplotlib.text.Text object at 0x2aa8890> In [9]: plt.xlabel('Samples') Out[9]: <matplotlib.text.Text object at 0x2aa6150> In [10]: plt.ylabel('Values Measured') Out[10]: <matplotlib.text.Text object at 0x2aa6d10> In [11]: plt.legend(loc='upper left') Out[11]: <matplotlib.legend.Legend object at 0x2ac5c50> In [12]: plt.show()
A very nice looking plot can be obtained with just...