4

I'am trying to plot time serie with pyqtgraph. I've read this, this and this. But i'am not sure how to correctly use it.

My plot is a plot widget, and i use it this way:

graph.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})

where TimeAxisItem is defined like this:

class TimeAxisItem(pg.AxisItem):
    def __init__(self, *args, **kwargs):
       super().__init__(*args, **kwargs)

    def tickStrings(self, values, scale, spacing):
        # PySide's QTime() initialiser fails miserably and dismisses args/kwargs
        return [useful_values_dict['useful_data']['data']['ISO_dates']]

where ISO_dates is a list of date and time in ISO format

I've also tried this:

graph.plotItem.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})

but with no effects (axis strings are stil numbers).

Then i tried to use the DateTimeAxis.py, this way:

date_axis = pg.DateAxisItem('bottom', pen=None, linkView=None, parent=None, maxTickLength=-1, showValues=True)
date_axis.tickStrings(useful_values_dict['useful_data']['data']['timestamp_dates'],1, 1)

but i get an error:

File "C:\Python34\lib\site-packages\pyqtgraph\graphicsItems\DateAxisItem.py", line 161, in tickStrings
format_strings.append(x.strftime(tick_spec.format))
AttributeError: 'NoneType' object has no attribute 'format'
Community
  • 1
  • 1
beni
  • 105
  • 3
  • 9

1 Answers1

7

I finally solved my problem, it was quite easy.

I just needed to initialize my plot widget that way:

    date_axis = pg.graphicsItems.DateAxisItem.DateAxisItem(orientation = 'bottom')
    self.graph = pg.PlotWidget(axisItems = {'bottom': date_axis})

and plot my data that way:

    graph.plot(x = useful_values_dict['useful_data']['data']['timestamp_dates'],
               y = useful_values_dict['useful_data']['data'][raw_header],
               pen=pg.mkPen(color=colors[count],width=1,style=QtCore.Qt.SolidLine))

with x data as an array of timestamp.

Thanks !

beni
  • 86
  • 5
  • I wish i could but i don't remember neither my password nor my e-mail for the account which i asked the question with. – beni Mar 22 '15 at 12:19