我通过删除现有的安装确保没有其他pyqtgraph:
rm -rf ~idf/anaconda/lib/python2.7/site-packages/pyqtgraph*
我使用
下载了带有date-axis-item的分支git clone -b date-axis-item https://github.com/3rdcycle/pyqtgraph.git
然后在下载的分支目录
中运行python setup.py install
当我尝试运行此程序时,它失败并带有
[idf@localhost python]$ python AxisExample1.py
Traceback (most recent call last):
File "AxisExample1.py", line 12, in <module>
axis = pg.DateTimeAxisItem(orientation='bottom')
AttributeError: 'module' object has no attribute 'DateTimeAxisItem'
请注意我做错了什么?
# -*- coding: utf-8 -*-
"""
Description of example
"""
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
pg.mkQApp()
axis = pg.DateTimeAxisItem(orientation='bottom')
pw = pg.PlotWidget(axisItems={'bottom': axis})
pw.setWindowTitle('pyqtgraph example: DateTimeAxis')
pw.show()
pw.setXRange(1383960000, 1384020000)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
答案 0 :(得分:1)
git clone https://github.com/3rdcycle/pyqtgraph.git
git checkout origin / date-axis-item
pip uninstall pyqtgraph
python setup.py install
并将您的示例更改为:
# -*- coding: utf-8 -*-
"""
Description of example
"""
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
pg.mkQApp()
axis = pg.DateAxisItem(orientation='bottom')
pw = pg.PlotWidget(axisItems={'bottom': axis})
pw.setWindowTitle('pyqtgraph example: DateTimeAxis')
pw.show()
pw.setXRange(1383960000, 1384020000)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exe
应该有用。