我正在编写一个接口(interface)来在 Matplotlib 中绘制散点图,并且我希望能够从 python 脚本访问数据。
现在,我的界面正在执行:
scat = self.axes.scatter(x_data, y_data, label=label, s=size)
带有标准axes.plot
我可以做这样的事情:
line = self.axes.plot(x_data, y_data)
data = line[0].get_data()
这样就可以了。我想要的是类似的东西,但带有散点图。
有人可以建议类似的方法吗?
最佳答案
使用 PathCollection
绘制散点
图,因此 x、y 位置称为“偏移量”:
import numpy as np
import matplotlib.pyplot as plt
f, ax = plt.subplots()
scat = ax.scatter(np.random.randn(10), np.random.randn(10))
print scat.get_offsets()
[[-0.17477838 -0.47777312]
[-0.97296068 -0.98685982]
[-0.18880346 1.16780445]
[-1.65280361 0.2182109 ]
[ 0.92655599 -1.40315507]
[-0.10468029 0.82269317]
[-0.09516654 -0.80651275]
[ 0.01400393 -1.1474178 ]
[ 1.6800925 0.16243422]
[-1.91496598 -2.12578586]]
关于python - 从 Matplotlib 中的散点图提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27849989/