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 0x7ff410e30ca0>]
_images/1d930720ce9c13d7ac49dcb345e942b92b97650bb4e241a6ea6085bf561bca09.png
# Another line from (2, 6) to (8, 1)
plt.plot([2, 8], [6, 1])
[<matplotlib.lines.Line2D at 0x7ff410d36440>]
_images/498566b379566e996c048c9b50e1092f50337dab575f58f077e92e6780843529.png