如何更新 tkinter 中 matplotlib 图形中的 x 限制 [英] how do I update the x limits in a matplotlib figure in tkinter

查看:69
本文介绍了如何更新 tkinter 中 matplotlib 图形中的 x 限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TKinter 制作了一个 GUI,它可以读取来自安捷伦示波器的示波器跟踪.我想在更改时间/格时更新x轴.要更新x和y数据,我使用 set_xdata set_ydata .是否有类似的更新 x 限制的方法?

I made a GUI with TKinter that reads a scope trace from a agilent scope. I want the x axis to update when I change time/div. To update the x and y data I use set_xdata and set_ydata. Is there a similar method for updating the x limits?

推荐答案

您需要了解一些对象层次结构.您正在 Line2D 对象上调用 set_xdata ,该对象是与 Axes 对象(该对象关联的 Artist 处理与 Figure 对象(将一堆轴对象组合在一起,处理窗口管理器)关联的日志与线性、x/y 限制、轴标签、刻度位置和标签等内容(用于 gui)等)和一个 canvas 对象(它实际上处理将所有其他对象转换为屏幕上的图片).

You need to understand a bit of the object hierarchy. You are calling set_xdata on a Line2D object, which is an Artist which is associated with an Axes object (which handles things like log vs linear, the x/y limits, axis label, tick location and labels) which is associated with a Figure object (which groups together a bunch of axes objects, deals with the window manager (for gui), ect) and a canvas object (which actually deals with translating all of the other objects to a picture on the screen).

如果您使用 Tkinter,我假设您有一个 axes 对象(我将其称为 ax).

If you are using Tkinter, I assume that you have an axes object, (that I will call 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.

so to update the data in the line, you need to update my_line, to update the axes limits, you need to update ax.

set_xlim doc set_ylim doc

这篇关于如何更新 tkinter 中 matplotlib 图形中的 x 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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