pyqtgraph,绘制时间序列 [英] pyqtgraph, plotting time series
问题描述
我正在尝试使用pyqtgraph绘制时间序列。我已阅读此,这和此。但是我不确定如何正确使用它。
我的情节是情节小部件,我以这种方式使用它:
graph.plot(aerosol_data,pen = pg.mkPen(color = colors [count],width = 1,style = QtCore.Qt.SolidLine),axisItems = {'bottom':TimeAxisItem(orientation ='bottom')' })
其中TimeAxisItem的定义如下:
class TimeAxisItem(pg.AxisItem):
def __init __(self,* args,** kwargs):
super().__ init __(* args, ** kwargs)
def tickStrings(self,values,scale,space):
#PySide的QTime()初始化程序失败,并拒绝args / kwargs
return [use_values_dict ['有用的数据'] ['数据'] ['ISO_dates']]
其中ISO_dates是日期列表和时间以ISO格式
我也尝试过这样:
graph.plotItem.plot(aerosol_data,pen = pg.mkPen(color = colors [count],width = 1,style = QtCore.Qt.SolidLine),axisItems = {'bottom':TimeAxisItem(or ientation ='bottom')})
,但没有任何影响(轴字符串是斯蒂尔数字)。 / p>
然后我尝试通过以下方式使用DateTimeAxis.py:
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)
但我得到一个错误:
文件 C:\Python34\lib\site-packages\pyqtgraph\graphicsItems\DateAxisItem.py,第161行,以tickStrings
format_strings.append(x.strftime(tick_spec.format))为单位。
AttributeError:'NoneType'对象没有属性'format'
我终于解决了我的问题,这很容易。
我只需要以这种方式初始化绘图小部件:
date_axis = pg.graphicsItems.DateAxisItem.DateAxisItem(orientation = 'bottom')
self.graph = pg.PlotWidget(axisItems = {'bottom':date_axis})
并以这种方式绘制数据:
graph.plot(x = utility_values_dict ['useful_data'] ['数据'] ['timestamp_dates'],
y =有用值_dict ['有用数据'] ['数据'] [原始标题],
pen = pg.mkPen(color = colors [count],width = 1, style = QtCore.Qt.SolidLine))
,其中x数据作为时间戳数组。
谢谢!
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'
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 !
这篇关于pyqtgraph,绘制时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!