官方文档:
setXRange(min, max, padding=None, update=True)[source]
Set the visible X range of the view to [min, max]. The padding argument causes the range to be set larger by the fraction specified. (by default, this value is between the default padding and 0.1 depending on the size of the ViewBox)
setRange的padding参数为none时会根据屏幕大小自动放大range,要设置padding为0
如:
range0 = self.ui.plot_widget.viewRange()[0] # list第一个项为xRange,第二个为yRange
self.ui.plot_widget.setRange(xRange=[range0[0], range0[1]], padding=0)