我正在尝试绘制在 x 轴上有时间戳并在 y 轴上计数的折线图。matplotlib 绘图的输出使用 mpld3 save_html() 方法存储在一个 html 文件中。当代码在windows平台上运行时,输出呈现如下:
windows输出(html渲染-正确输出)
然而,我的代码需要在亚马逊云(Arch linux)上运行,它将 x 轴刻度输出为无符号整数,如下所示(图表看起来不同,因为它是在几分钟后拍摄的):-
在这里寻找专家指导,了解为什么它没有显示实际的日期/时间戳。
我在下面发布了一个小的更改的代码。我的带时间戳的数据源是本地定义的。其他一切都是一样的。请注意,这不会呈现与上面相同的图形,因为数据源不同。
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')