我的对象列表“dateIndex”如下所示。。。你知道吗
2013-10-16 12:42:49
2013-10-16 12:42:49
2013-10-16 12:42:49
2013-10-16 12:42:49
2013-10-17 09:09:53
2013-10-17 09:10:40
2013-10-17 09:10:42
2013-10-17 09:20:02
2013-10-17 09:30:02
2013-10-17 09:40:02
2013-10-17 09:48:52
2013-10-17 09:59:01
我需要把这些日期和时间写在x标签上,但我不知道怎么写。你知道吗
我的绘图功能:
def graphData(dateIndex,irValue):
fig = plt.figure()
ax1 = plt.subplot2grid((5,4), (0,0), rowspan=4, colspan=4)#, axisbg='#07000d')
ax1 = plt.subplot(1,1,1)
date = mdates.strpdate2num('%d-%m-%Y %H:%M:%S')
converters = { dateIndex:mdates.strpdate2num('%d-%m-%Y %H:%M:%S') }
#this is where i get an error -> unhashable type: 'list'
ax1.plot(date,irValue)
ax1.grid(True)
ax1.spines['bottom'].set_color("#5998ff")
ax1.tick_params(axis='y')
ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax1.axis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y %H:%M:%S'))
您正在创建
mdates.strpdate2num
函数,但从未将其应用于实际的日期字符串。你知道吗下面给出了一个固定的
graphData
函数,其中使用了列表理解来应用该函数。我还修复了函数中的另外两个问题,即:应该使用plot_date
而不是plot
,并且在设置格式化程序时错过了xaxis
中的x
。你知道吗相关问题 更多 >
编程相关推荐