如何在不显示所有点的情况下绘制时间序列?
How to plot time series without showing all points?
我想用pyqtgraph绘制时间-价格曲线。
像这样:
我已经知道如何设置自定义 axisitem 参考
pyqtgraph : how to plot time series (date and time on the x axis)?
我的问题是是否有办法显示我需要刻度字符串而不是全部?
如何跳过这些刻度字符串
有一个演示和一些数据,例如:
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_()
如何避免一直显示刻度字符串?
当您定义 setTicks 时,您将每个刻度都定义为主要刻度。如果你改为给它两个列表,第二个列表将用于小刻度,请参阅:http://www.pyqtgraph.org/documentation/graphicsItems/axisitem.html#pyqtgraph.AxisItem.setTicks
对于您的问题,您可以将 xtickts 更改为
xtickts=[list(xDict.items())[::2], list(xDict.items())[1::2]]
然后,如果您缩放,则小音符的字符串将变得可见。
同样的问题:
我想用pyqtgraph绘制时间-价格曲线。
像这样:
我已经知道如何设置自定义 axisitem 参考
pyqtgraph : how to plot time series (date and time on the x axis)?
我的问题是是否有办法显示我需要刻度字符串而不是全部?
如何跳过这些刻度字符串
有一个演示和一些数据,例如:
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_()
如何避免一直显示刻度字符串?
当您定义 setTicks 时,您将每个刻度都定义为主要刻度。如果你改为给它两个列表,第二个列表将用于小刻度,请参阅:http://www.pyqtgraph.org/documentation/graphicsItems/axisitem.html#pyqtgraph.AxisItem.setTicks
对于您的问题,您可以将 xtickts 更改为
xtickts=[list(xDict.items())[::2], list(xDict.items())[1::2]]
然后,如果您缩放,则小音符的字符串将变得可见。
同样的问题: