python - 如何从 matplotlib 图中提取数据

标签 python matplotlib

我有一个 wxPython 程序,它从不同的数据集读取数据,对数据执行各种类型的简单即时分析,并将数据集的各种组合绘制到 matplotlib Canvas 。我希望有机会将当前绘制的数据转储到文件中,以便以后进行更复杂的分析。

问题是:matplotlib 中是否有任何方法允许访问当前在 matplotlib.Figure 中绘制的数据?

最佳答案

Jakub 关于修改 Python 脚本以直接从将数据发送到图中的源写出数据是正确的;这就是我喜欢这样做的方式。但作为引用,如果您确实需要从绘图中获取数据,我认为应该这样做

gca().get_lines()[n].get_xydata()

或者,您可以分别获取 x 和 y 数据集:

line = gca().get_lines()[n]
xd = line.get_xdata()
yd = line.get_ydata()

关于python - 如何从 matplotlib 图中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8938449/

相关文章:

Python 正则表达式。删除 ':' 之后的所有字符(包括行尾和特定字符串除外)

python - pyplot : Plot a curve with ticks on one side

python - matplotlib:使用 bbox_inches ='tight' 保存无花果忽略注释

python - 如何在 matplotlib 中更改 x 轴和 y 轴?

Python 使用数据/时间作为 x 轴?

python - 我已经用 conda 安装了 pil,但是当我尝试导入它时,它说不存在模块

python - PyQt 与继承的混淆

python - Tkinter 小部件打开两个窗口

python - 如何将 gobject.Gtype 参数传递给函数中的 Gtk.ListStore

python - 在 png 上绘制 matplotlib 散点图