0

I am trying to plot an line graph which has timestamp on x-axis and count on y-axis. The output of matplotlib plot is stored in an html file using mpld3 save_html() method. when the code is run on windows platform, the output is rendered as follows:

windows output ( html rendering- correct output)

enter image description here

However my code needs to run on Amazon cloud ( Arch linux) where it outputs the x-axis ticks as unsigned int as shown below ( graph looks different as it was taken some minutes later):- enter image description here

Looking for experts guidance here on why it is not showing the actual date/timestamp.

I am posting the code below which a small change. My datasource with timestamp is locally defined. Everything else is the same. Note that this won't render the same graph as above as the datasource is different.

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')
sunny
  • 643
  • 2
  • 11
  • 29
  • I guess the formatter is not correctly recognized and converted to mpld3. As said in the previous question of yours, mpld3 needs to recreate the plot and it will fail to do so in many non-standard cases. – ImportanceOfBeingErnest Jan 14 '18 at 12:27
  • Thanks for the info. any workaround ?. Are there other means of creating static html files ? – sunny Jan 15 '18 at 02:42
  • Comming back to this issue, I found that running the above code actually produces [the correct plot for me](https://i.stack.imgur.com/4kKMU.png). The problem may be a little more involved, having to do with differing pandas versions in use. Are you able to check which versions are being used locally and on the amazon server? Do they differ? You may try adding `import pandas.plotting._converter as pandacnv; pandacnv.register()` to your code and recheck. – ImportanceOfBeingErnest Jan 21 '18 at 00:05

0 Answers0