从Matplotlib轴对象获取数据 [英] Getting data from matplotlib axes object

查看:45
本文介绍了从Matplotlib轴对象获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定 matplotlib .在对象上是否缺少我要获取x/的属性?有数据值吗?

I'm trying to determine what the data points are on a matplotlib axes. Is there an attribute I'm missing on the Axes object to get the x/y data values?

例如,假设我的代码通过了一条线图,而我想打印出绘制的x/y值.

For example, say my code is passed a line plot, and I want to print out the x/y values that are plotted.

推荐答案

你的 plot 调用会给你一个 lines.Line2D,它有 get_xdata(orig=True)get_ydata(orig=True) 方法.

Your plot call will give you a lines.Line2D, which has the get_xdata(orig=True) and the get_ydata(orig=True) methods.

您可以检查 LineesD 实例的 axes.get_children().

请注意,从软件设计的角度来看,您所做的事情听起来很可怕.您应该为打印原始数据的 plot 实现一个包装器.

Note that what you're doing sounds horrible from a software design point of view. You should rather implement something like a wrapper for plot that prints your raw data.

@JRichardSnape补充说,如果您的绘图只是线条,则可以使用 get_lines(),而不是过滤 get_children()的输出.

@JRichardSnape adds that iff your plot is only lines, you can use get_lines() rather than filtering the output of get_children().

这篇关于从Matplotlib轴对象获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆