Lines connecting the coordinates with the axis of the graph in matplotlib

  matplotlib, python

let’s say for example that I have this piece of code:

import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [1,4,9,16]
plt.plot(x, y, 'ro')
plt.axis([0, 6, 0, 20])

for i_x, i_y in zip(x, y):
    plt.text(i_x, i_y, '({}, {})'.format(i_x, i_y))

plt.show()

My question is, how do I draw a dashed line that connects the coordinates in the graph with the two axis? Can I do that in matplotlib?

Thank you so much in advance!

Source: Python Questions

LEAVE A COMMENT