我在下面列出了一个时间列表:
time_list = [63158,63159,63200,63201,63202]
但我想要这样的图形:
time_list = [6:31:58,6:31:59,6:32:00,6:32:01,6:32:02]
在63159和63200之间,不应该表现得好像其中有40个数字。你知道吗
我可以将它与matplotlib库一起使用,但就我而言wxmpl比它更好。你知道吗
所以我的问题是除了matplotlib之外,我如何在任何绘图库中使用时间格式?你知道吗
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
from wxmplot import PlotPanel
import wx
x=[]
class MyFrame1 ( wx.Frame ):
def __init__( self, parent, **kws ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 595,476 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL, **kws )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
bSizer2 = wx.BoxSizer( wx.VERTICAL )
gSizer1 = wx.GridSizer( 0, 0, 0, 0 )
###############################
self.plotpanel = PlotPanel(self)
###############################
self.toggleBtn4 = wx.ToggleButton( self, wx.ID_ANY, u"Plot", wx.DefaultPosition, wx.DefaultSize, 0 )
gSizer1.Add( self.toggleBtn4, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
bSizer2.Add( gSizer1, 1, wx.EXPAND, 5 )
bSizer1.Add( bSizer2, 1, wx.EXPAND, 5 )
bSizer3 = wx.BoxSizer( wx.VERTICAL )
bSizer3.Add(self.plotpanel, 1, wx.ALL|wx.EXPAND, 0 )
bSizer1.Add( bSizer3, 3, wx.EXPAND, 5 )
self.SetSizer( bSizer1 )
#bSizer1.Fit(self)
self.Centre( wx.BOTH )
# Connect Events
self.toggleBtn4.Bind( wx.EVT_TOGGLEBUTTON, self.plot )
def plot( self, event ):
time_list = [63150,63151,63152,63153,63154,63155,63156,63157,63158,63159,63200,63201,63202,63203,63204,63205,63206,63207,63208,63209,63210]
y = [100,101,105,124,119,134,89,147,98,75,52,150,143,156,99,13,54,68,100,85,87]
obj = event.GetEventObject()
isPressed = obj.GetValue()
if isPressed:
for i in time_list:
hour = i//10000
minute = (i//100)%100
second = i%100
time_new = hour*3600 + minute*60 + second
x.append(time_new)
print("i : ",i)
print("zaman : ",time_new)
time4 = time.strftime('%H:%M:%S', time.gmtime(time_new))
print("time : ",time4,"\n")
self.plotpanel.plot(x, y)
else:
self.Destroy()
if __name__ == "__main__":
app = wx.App(False)
f = MyFrame1(None)
f.Show(True)
app.MainLoop()
目前,
wxmplot.PlotPanel.plot()
(和.oplot()
)只支持在使用plot(xdata, ydata, use_dates=True)
和xdata
作为Unix时间戳时将xdata
自动转换为日期时间值。你知道吗也就是说,
use_dates=True
确实如此因此,我认为您必须将时间数据的自定义编码转换为更标准的时间表示。我想你有两个选择:
将
time_list
数据转换为时间戳(从epoch开始的秒数)并使用use_dates=True
。将
time_list
数据转换为matplotlib.dates
的实例,可能使用datetime
作为中间形式并使用use_dates=False
。相关问题 更多 >
编程相关推荐