Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the seconds from x-axis time labels in matplotlib

I would like to remove seconds from my x-axis labels as they are unnecessary.

Also I want to center align the tick labels instead of have them positioned to the left of the tick mark.

Any suggestions on how to do this?

Here is some of the code that I've used if this helps

fig=plt.figure()
ax=fig.add_subplot(111)
line1 = plot(table.index,table[data],color=colors[0])

fig.autofmt_xdate(rotation=0)   

tickFormat =  matplotlib.ticker.LinearLocator(numticks=5)
ax.xaxis.set_major_locator(tickFormat)            

enter image description here

like image 279
Osmond Bishop Avatar asked Feb 17 '23 19:02

Osmond Bishop


1 Answers

from matplotlib.dates import DateFormatter
formatter = DateFormatter('%H:%M')
plt.gcf().axes[0].xaxis.set_major_formatter(formatter)  
like image 121
Osmond Bishop Avatar answered Feb 19 '23 10:02

Osmond Bishop