我使用 TKinter 制作了一个 GUI,可以从安捷伦示波器读取示波器轨迹。我希望 x 轴在更改时间/格时更新。更新我使用的 x 和 y 数据set_xdata
and set_ydata
。是否有类似的方法来更新 x 限制?
您需要了解一些对象层次结构。你正在呼唤set_xdata
on a Line2D
对象,这是一个Artist
这与一个相关联Axes
对象(处理诸如对数与线性、x/y 限制、轴标签、刻度位置和标签等内容)与Figure
对象(将一堆轴对象组合在一起,处理窗口管理器(对于 GUI)等)和一个canvas
对象(实际上涉及将所有其他对象转换为屏幕上的图片)。
如果您正在使用 Tkinter,我假设您有一个axes
对象,(我称之为ax
).
ax = fig.subplot(111) # or where ever you want to get you `Axes` object from.
my_line = ax.plot(data_x, data_y)
# whole bunch of code
#
# more other code
# update your line object
my_line.set_xdata(new_x_data)
my_line.set_ydata(new_y_data)
# update the limits of the axes object that you line is drawn on.
ax.set_xlim([top, bottom])
ax.set_ylim([left, right])
因此要更新该行中的数据,您需要更新my_line
,要更新轴限制,您需要更新ax
.
set_xlim
doc http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_xlim and set_ylim
doc http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_ylim
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)