繁体   English   中英

如何在tkinter中更新matplotlib图中的x限制

[英]how do I update the x limits in a matplotlib figure in tkinter

我使用TKinter制作了一个GUI,该GUI从安捷伦范围读取范围跟踪。 我希望在更改时间/格时更新x轴。 要更新x和y数据,我使用set_xdata和set_ydata。 是否有类似的方法来更新x限制?

您需要了解一些对象层次结构。 要调用set_xdata一个上Line2D对象,它是一个Artist ,其具有相关联的Axes对象(处理诸如日志VS线性的东西,在X / Y的限制,轴线标签,蜱位置和标签),其与相关联的Figure对象(将一堆轴对象组合在一起,处理窗口管理器(对于gui),ect等)和一个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 文档set_ylim 文档

pyplot.xlim()函数更改(当前轴的)x轴的范围。

轴的set_xticks()方法设置刻度。 当前轴可以通过gca()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM