使用mpld3保存为html文件的折线图将时间戳刻度显示为unsigned int

时间:2018-01-13 23:54:59

标签: python-3.x matplotlib mpld3

我正在尝试绘制一条线图,该线图在x轴上有时间戳并在y轴上计数。 matplotlib图的输出使用mpld3 save_html()方法存储在html文件中。当代码在Windows平台上运行时,输出呈现如下:

windows输出(html渲染 - 正确输出)

enter image description here

但是我的代码需要在亚马逊云(Arch linux)上运行,它将x轴刻度输出为unsigned int,如下所示(图表看起来不同,因为它在几分钟后拍摄): - enter image description here

在这里寻找专家指导,说明为什么它没有显示实际的日期/时间戳。

我发布的代码下面有一个小小的变化。带有时间戳的数据源是本地定义的。其他一切都是一样的。请注意,由于数据源不同,因此不会呈现与上面相同的图形。

fig2,ax2=plt.subplots() 
dsize=fig2.get_size_inches()    
fig2.set_size_inches((dsize[0]/2)*(1.5),(dsize[1]/2)*(1.25))
data=pd.DataFrame([['2017-12-01 11:55:01',5],['2017-12-01 13:55:03',10],['2017-12-01 16:55:01',3],['2017-12-01 16:55:01',12]],columns=['timestamp','count'])

tt=data['timestamp'].apply(lambda x: datetime.strptime(x,"%Y-%m-%d %H:%M:%S"))
tt1=tt.apply(lambda x: datetime(x.year,x.month,x.day,x.hour))
x=[i for k,i in enumerate(tt1)]
print (x)
y=[i for k, i in enumerate(data['count'])]
print(y)
ax2.minorticks_off()
ax2.tick_params(axis='x', which='major', pad=15)
plt.xticks(rotation=90)
line, =ax2.plot(x,y)
ax2.set_xlabel('Date')
ax2.set_ylabel('Count of Anomalies')
line.set_color("Red")
mpld3.save_html(fig2,'test2.html')

0 个答案:

没有答案