Plotting lines in matplotlib#

import matplotlib.pyplot as plt

To plot a line in matplotlib, use plot with the X coordinates as the first argument and the matching Y coordinates as the second argument:

# A line from (1, 2) to (7, 11)
plt.plot([1, 7], [2, 11])
[<matplotlib.lines.Line2D at 0x7fdf3d482ef0>]
_images/afcdfe8edc10f7834348ed1452c21890ed1f088016cb483022aba906e70f740c.png
# Another line from (2, 6) to (8, 1)
plt.plot([2, 8], [6, 1])
[<matplotlib.lines.Line2D at 0x7fdf3d36d8d0>]
_images/aad9884ee3aa349ba9086ac6a6fd9a238601db4539c5ae16dafeb21db4d7c1a6.png