![](/img/trans.png)
[英]How do you automatically update matplotlib subplot limits based on another's limits within Tkinter?
[英]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
。
pyplot.xlim()
函數更改(當前軸的)x軸的范圍。
軸的set_xticks()
方法設置刻度。 當前軸可以通過gca()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.