我使用pyqtgraph来绘制图形,其中我放置了一些文本(例如数据的最大值…)
我的问题是如何知道文本项输入的大小(高度、宽度)?它是为了控制它的位置,以避免在窗外。在
例如,我的代码可以是:
# -*- coding: utf-8 -*-
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
pg.setConfigOptions(antialias=True)
voieTT=np.ones(100)
voieTemps=np.ones(100)
for i in range(100):
voieTT[i]=np.random.random_sample()
voieTemps[i]=i
signemax=np.max(voieTT)
tmax=np.where(voieTT==np.max(voieTT))[0][0]
grapheTT = win.addPlot(enableMenu=False)
grapheTTVB=grapheTT.getViewBox()
grapheTT.plot(voieTemps, voieTT)
grapheTT.plot([tmax],[signemax],symbol='o',symbolSize=8)
grapheTT.showGrid(x=True, y=True)
textVmax = pg.TextItem(anchor=(0.5,1.5), border='w', fill=(0,0,255))
textVmax.setHtml('<div style="text-align: center"><span style="color: #FFF;">Vmax=%0.1f mm/s @ %0.1f s</span></div>'%(np.abs(signemax),tmax))
grapheTT.addItem(textVmax)
textVmax.setPos(tmax, signemax)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
相关问题 更多 >
编程相关推荐