你有你的時間戳轉換爲日期時間,然後使用matplotlib繪製它所需方式:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
time_arr =[1491343400.0, 1491343830.0, 1491344137.0, 1491344322.0, 1491344751.0, 1491412847.0, 1491413092.0, 1491413277.0, 1491413645.0, 1491413952.0, 1491414198.0, 1491414627.0, 1491418003.0, 1491418924.0, 1491419170.0, 1491419907.0, 1491420091.0, 1491421073.0, 1491422915.0, 1491423591.0, 1491423960.0, 1491424389.0, 1491426048.0, 1491426846.0, 1491427890.0, 1491428566.0, 1491428935.0]
# convert timestamp to datetime
x = [datetime.datetime.fromtimestamp(val) for val in time_arr]
print(x)
# random y values
y = np.random.rand(len(time_arr))
ax = plt.subplot(111)
ax.bar(x, y, width = 0.01)
# set datetime formatter for x axis
xfmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(xfmt)
# set ticks every 30 mins
ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=30))
# set fontsize of ticks
ax.tick_params(axis='x', which='major', labelsize=5)
# rotate ticks for x axis
plt.xticks(rotation=90)
plt.show()
你有大量的數據和蜱設定每6小時。
但是,如果打印X數組你得到的日期和時間,直到秒:
[datetime.datetime(2017, 4, 5, 8, 3, 20), datetime.datetime(2017, 4, 5, 8, 10, 30), datetime.datetime(2017, 4, 5, 8, 15, 37), datetime.datetime(2017, 4, 5, 8, 18, 42), datetime.datetime(2017, 4, 5, 8, 25, 51), datetime.datetime(2017, 4, 6, 3, 20, 47), datetime.datetime(2017, 4, 6, 3, 24, 52), datetime.datetime(2017, 4, 6, 3, 27, 57), datetime.datetime(2017, 4, 6, 3, 34, 5), datetime.datetime(2017, 4, 6, 3, 39, 12), datetime.datetime(2017, 4, 6, 3, 43, 18), datetime.datetime(2017, 4, 6, 3, 50, 27), datetime.datetime(2017, 4, 6, 4, 46, 43), datetime.datetime(2017, 4, 6, 5, 2, 4), datetime.datetime(2017, 4, 6, 5, 6, 10), datetime.datetime(2017, 4, 6, 5, 18, 27), datetime.datetime(2017, 4, 6, 5, 21, 31), datetime.datetime(2017, 4, 6, 5, 37, 53), datetime.datetime(2017, 4, 6, 6, 8, 35), datetime.datetime(2017, 4, 6, 6, 19, 51), datetime.datetime(2017, 4, 6, 6, 26), datetime.datetime(2017, 4, 6, 6, 33, 9), datetime.datetime(2017, 4, 6, 7, 0, 48), datetime.datetime(2017, 4, 6, 7, 14, 6), datetime.datetime(2017, 4, 6, 7, 31, 30), datetime.datetime(2017, 4, 6, 7, 42, 46), datetime.datetime(2017, 4, 6, 7, 48, 55)]
[繪製時間戳與Matplotlib(時/分/秒)的可能的複製(http://stackoverflow.com/questions/ 17709823 /繪製-時間戳小時 - 分 - 秒與 - matplotlib) – Serenity