Matplotlib - the first example

For the following examples, the figures are displayed as standard output by default; it is easier if you try them out while on standard output. If you have been following along the book via a virtual machine, it is recommended that you use the VM Window instead of SSH. If you do not have access to the standard output, you can save the figure and view it after you download it (as you will see soon). Note that you will need to set the $DISPLAY variable in some of the following graphs.

A line plot graph simply gives two lists of numbers that correspond to the x axis and y axis values:

>>> import matplotlib.pyplot as plt
>>> plt.plot([0,1,2,3,4], [0,10,20,30,40])
[<matplotlib.lines.Line2D object at 0x7f932510df98>]
>>> plt.ylabel('Something on Y')
<matplotlib.text.Text object at 0x7f93251546a0>
>>> plt.xlabel('Something on X')
<matplotlib.text.Text object at 0x7f9325fdb9e8>
>>> plt.show()

The graph will show as a line graph:

Matplotlib Line Graph

Alternatively, if you do not have access to standard output or have saved the figure first, you can use the savefig() method:

>>> plt.savefig('figure1.png')
or
>>> plt.savefig('figure1.pdf')

With this basic knowledge of graphing plots, we can now graph the results we received from SNMP queries.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.151.44