python - 为什么我的 pyqtgraph y 轴在 x 轴上方偏移?
问题描述
环境
- 蟒蛇 3.8.3
- pyqtgraph 0.11.0
- 视窗 10
信息
目前使用 pyqtgraph 库为基于 Qt 的桌面应用程序开发绘图功能,我一直看到 y 轴偏离 x 轴而不是紧密相交。
奇怪的是,我不记得前一段时间在使用 pyqtgraph 时看到过这个,但我想知道是否有人遇到过这个问题并修复了它。上面的图片是使用以下代码创建的,为了简单起见,我从 pyqtgraph 的示例目录中删除了这些代码。
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
app = pg.mkQApp()
mw = QtGui.QMainWindow()
mw.setWindowTitle('pyqtgraph example: PlotWidget')
mw.resize(800,800)
cw = QtGui.QWidget()
mw.setCentralWidget(cw)
l = QtGui.QVBoxLayout()
cw.setLayout(l)
pw = pg.PlotWidget(name='Plot1') ## giving the plots names allows us to link their axes together
l.addWidget(pw)
mw.show()
## Create an empty plot curve to be filled later, set its pen
p1 = pw.plot()
p1.setPen((200,200,100))
## Add in some extra graphics
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 5e-11))
rect.setPen(pg.mkPen(100, 200, 100))
pw.addItem(rect)
pw.setLabel('left', 'Value', units='V')
pw.setLabel('bottom', 'Time', units='s')
pw.setXRange(0, 2)
pw.setYRange(0, 1e-10)
def rand(n):
data = np.random.random(n)
data[int(n*0.1):int(n*0.13)] += .5
data[int(n*0.18)] += 2
data[int(n*0.1):int(n*0.13)] *= 5
data[int(n*0.18)] *= 20
data *= 1e-12
return data, np.arange(n, n+len(data)) / float(n)
def updateData():
yd, xd = rand(10000)
p1.setData(y=yd, x=xd)
## Start a timer to rapidly update the plot in pw
t = QtCore.QTimer()
t.timeout.connect(updateData)
t.start(50)
lr = pg.LinearRegionItem([1, 30], bounds=[0,100], movable=True)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
解决方案
推荐阅读
- excel - Excel 中 INDEX 的替代方案
- swift - 为什么不能在方法中刷新文本字段?
- google-chrome - 使用浏览器访问 url
- function - 在 julia 函数中定义变量时,我在该行收到有关未定义变量的错误
- ios - IOS/Xcode:完成块中的断点可能吗?
- php - 尽管执行中提供了参数值,但语句不返回任何记录
- ios - 如何在 UITextView swift4 中居中 AttributedText 链接
- excel - 通过excel vba同时追加和更新访问
- java - 找到数字 600851475143L 的最大素数
- ajax - Django 文档上的 CSRF 令牌名称与 AJAX 标头中变量的实际名称不匹配