Well now I have a solution to plot the values/dates correctly.
dateValues = self.datesToValues(dates)
lastDateVal = dateValues[len(dateValues) - 1]
log.info(lastDateVal)
draw = TimeScaleDraw(dates[0])
self.curve.setData(dateValues, numvalues)
def datesToValues(self, dates):
refDate = dates[0].toJulianDay()
values = []
for d in dates: values.append(float(d.toJulianDay() - refDate))
return values
dateValues = self.datesToValues(dates)
div = QwtScaleDiv()
lastDateVal = dateValues[len(dateValues) - 1]
log.info(lastDateVal)
draw = TimeScaleDraw(dates[0])
self.qwtPlot.setAxisScaleDraw(QwtPlot.xBottom, draw)
self.qwtPlot.setAxisScale(QwtPlot.xBottom, 0.0, lastDateVal)
self.curve.setData(dateValues, numvalues)
self.qwtPlot.replot()
def datesToValues(self, dates):
refDate = dates[0].toJulianDay()
values = []
for d in dates: values.append(float(d.toJulianDay() - refDate))
return values
To copy to clipboard, switch view to plain text mode
def __init__(self, refDate):
self.refDate = refDate.toJulianDay()
self.setLabelAlignment(Qt.AlignLeft | Qt.AlignBottom)
self.setLabelRotation(270)
def label(self, value):
next
= QDate.
fromJulianDay(value
+ self.
refDate).
toString("dd.MM.yyyy")
class TimeScaleDraw(QwtScaleDraw):
def __init__(self, refDate):
QwtScaleDraw.__init__(self)
self.refDate = refDate.toJulianDay()
self.setLabelAlignment(Qt.AlignLeft | Qt.AlignBottom)
self.setLabelRotation(270)
def label(self, value):
next = QDate.fromJulianDay(value + self.refDate).toString("dd.MM.yyyy")
return QwtText(next)
To copy to clipboard, switch view to plain text mode
It is not nice, but it's working.
Now I want to have changing labels/ticks.
For Example:
more than 2 years: label = 2010, 2011, 2012..
more than 6 months = Mar 2010, Apr 2010 ...
How do I implement this?
I mean something like this:
if dx > 365+366: #zwei Jahre
format = "YYYY"
Bookmarks