我想用pyqtgraph绘制时间 - 价格曲线。
像这样:
我已经知道如何设置自定义axisitem参考
我的问题是,是否有办法显示我需要刻度字符串而不是全部?
如何跳过这些刻度线
有一个演示和一些数据,例如:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore
time=['09:38:21','09:37:41','09:37:16','09:37:11','09:36:46',
'09:36:31','09:36:01','09:35:36','09:35:31','09:35:26',
'09:35:06','09:34:46','09:34:06','09:33:41','09:33:36',
'09:33:21','09:33:16','09:33:11','09:33:01','09:32:46',
'09:32:36','09:32:26','09:32:16','09:32:01','09:31:46',
'09:31:41','09:31:21','09:30:46','09:30:06','09:25:06']
price=[6.08,6.08,6.07,6.09,6.09,6.09,6.09,6.09,6.08,6.09,6.09,
6.09,6.09,6.07,6.07,6.06,6.06,6.06,6.06,6.06,6.07,6.08,
6.08,6.07,6.07,6.07,6.08,6.08,6.08,6.09 ]
xDict=dict(enumerate(time))
xValue=list(xDict.keys())
win = pg.GraphicsWindow()
bottomAxis = pg.AxisItem(orientation='bottom')
plot = win.addPlot(axisItems={'bottom': bottomAxis},name='price')
xtickts=[xDict.items()]
bottomAxis.setTicks(xtickts)
plot.plot(xValue,price)
if __name__ == '__main__':
import sys
if sys.flags.interactive != 1 or not hasattr( QtCore, 'PYQT_VERSION' ):
pg.QtGui.QApplication.exec_()
如何避免显示所有时间刻度字符串?
答案 0 :(得分:0)
定义setTicks时,将每个tick定义为主要滴答。如果您改为给它两个列表,则第二个列表将用于次要刻度,请参阅:http://www.pyqtgraph.org/documentation/graphicsItems/axisitem.html#pyqtgraph.AxisItem.setTicks
对于您的问题,您可以将xtickts更改为
xtickts=[list(xDict.items())[::2], list(xDict.items())[1::2]]
然后,如果你缩放字符串,那么minorticks就会变得可见。