O'Reilly logo

Matplotlib for Python Developers by Sandro Tosi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required