我有这个代码:
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()
我想从我的绘图中获取坐标。不幸的是我不知道该怎么做。我知道这可能很愚蠢,但说真的,我找不到办法做到这一点。
最佳答案
您可以使用lines2D对象的get_data()
方法从数据中获取坐标,参见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()
给出
(array([1, 2, 3, 4]), array([5, 6, 7, 4]))
如果无法直接使用plot命令保存线条列表,则可以通过ax.get_lines()
方法从ax对象中获取它。
关于python - 从 `matplotlib.pyplot.plot`获取点坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29832770/