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 0x7f8fdc9e6bf0>]
_images/f897875df94aa12ce0b3838366cbbbc7e86dfed9900519cf556ca4874b594d3f.png
# Another line from (2, 6) to (8, 1)
plt.plot([2, 8], [6, 1])
[<matplotlib.lines.Line2D at 0x7f8fdc8d1510>]
_images/699786d9d0f01ba07e47933d0f09db36abf3f2347e84823218ed94321fc55ede.png