0
我访问了互联网吨的网页,但只有在C中的例子,我不明白如何在Python中做到这一点。有人能帮我吗。 我使用Pyqt设计器和Python 2.7。我需要在使用qwtplot的GUI上绘制日期图。如何把日期放在python的xqwtplot轴上?
我访问了互联网吨的网页,但只有在C中的例子,我不明白如何在Python中做到这一点。有人能帮我吗。 我使用Pyqt设计器和Python 2.7。我需要在使用qwtplot的GUI上绘制日期图。如何把日期放在python的xqwtplot轴上?
你需要一个QwtScaleDraw类例如为:
class TimeScaleDraw(QwtScaleDraw):
def __init__(self, baseTime, *args):
QwtScaleDraw.__init__(self, *args)
self.baseTime = baseTime
def label(self, value):
upTime = self.baseTime.addSecs(int(value))
return QwtText(upTime.toString())
那么您修改x轴与此代码:
self.setAxisScaleDraw(
QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.upTime()))
其中自我的基类是QwtPlot。 cpuStat.upTime()返回一个QTime实例。值代表您的时间数据点之一。这段代码来自cpuDemo示例代码。
得到这个例子cpuDemo使用python xy 2.7。对进口模块进行以下更改:
import os
import sys
import numpy as np
from PyQt4.QtGui import (QApplication, QColor, QBrush, QWidget, QVBoxLayout,
QLabel)
from PyQt4.QtCore import QRect, QTime
from PyQt4.QtCore import Qt
from PyQt4.Qwt5 import (QwtPlot, QwtPlotMarker, QwtScaleDraw, QwtLegend, QwtPlotCurve,
QwtPlotItem, QwtText)#, QwtLegendData
然后注释掉所有图例行。
我采用了这段代码来使用QDateTime类。这里是一个片段:
from PyQt4 import QtCore, QtGui, Qt
from PyQt4 import Qwt5
class TimeScaleDraw(Qwt5.QwtScaleDraw):
def __init__(self, *args):
Qwt5.QwtScaleDraw.__init__(self,unixBaseTime *args)
self.basetime=unixBaseTime
self.fmt='h:mm\nd-MMM-yyyy'
def label(self, value):
dt = QtCore.QDateTime.fromMSecsSinceEpoch((value+self.basetime))
return Qwt5.QwtText(dt.toString(self.fmt))
...
class Ui_TabWidget(object):
def setupUi(self, TabWidget):
self.qwtPlot = Qwt5.QwtPlot()
self.qwtPlot.setAxisScaleDraw(Qwt5.QwtPlot.xBottom, TimeScaleDraw(unixBaseTime))
欣赏漂亮的图片