简体   繁体   中英

Getting point coordinates from `matplotlib.pyplot.plot`

I have this code:

import matplotlib.pyplot as plt
self.ax = plt.subplot(111)
cords = self.get_list_of_cords()
plt.plot(cords[0], cords[1], 'o', color='b')
plt.show()

I want to get back coordinates from my plot. Unfortunately I can't figure out how to do that. I know it may be silly, but seriously I can't find a way to do it.

You can get the coordinates from the data with the get_data() method of the lines2D object, see Docu :

import matplotlib.pyplot as plt
ax = plt.subplot(111)
li = ax.plot([1,2,3,4],[5,6,7,4], 'o-', color='b')
print li[0].get_data()

gives

(array([1, 2, 3, 4]), array([5, 6, 7, 4]))

If you cannot save the list of lines directly with the plot command, you can get it from the ax object by means of the ax.get_lines() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM