此code记录横轴的时间表示
import numpy as np
import pandas as pd
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
plt.figure(11)
x = np.array([ datetime.fromtimestamp(s) for s in time_data ])
x = pd.to_datetime(x)
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))#显示为小时和分钟
plt.gca().xaxis.set_major_locator(mdates.MinuteLocator(interval=150))#Minute也可以换成时间,天
plt.bar(x[:],data[:],width=0.0001,align='center')
plt.savefig('stats_time.eps',format = 'eps')
plt.show()
网友评论