python - Y 轴格式从秒到 HH:mm
解决方案
Try this code:
import matplotlib.pyplot as plt
from matplotlib import dates
# fake data
arr_data = range(0, 4)
arr_secs = [52000, 53000, 54000, 55000]
# format seconds to date with this format '%H:%M:%S'
arr__secs_formatted = list(map(datetime.datetime.strptime, map(lambda s: time.strftime('%H:%M:%S', time.gmtime(s)), arr_secs), len(arr_secs)*['%H:%M:%S']))
fig, ax = plt.subplots()
ax.plot(arr_data, arr_secs_formatted, 'ro-')
# set your date formatter whit this format '%H:%M'
formatter = dates.DateFormatter('%H:%M')
ax.yaxis.set_major_formatter(formatter)
plt.show()
推荐阅读
- javascript - 使用 Tabulator 分页的所需页面
- json - 在 powershell 中使用地址作为 JSON 键值
- python - 数据帧转换时间戳和字符串
- java - androidx.security 依赖问题
- javascript - 从 module.config 调用 stateProvider 解析中的 Service 函数
- javascript - 使用 mobx observe 检测嵌套对象的变化
- php - __SoapClient - SOAP-ERROR: Encoding: object has no 'auth' property
- javascript - 无法更改 Select2 中某个选项的字体大小
- karate - 如何仅为更改的微服务执行空手道脚本
- java - Springboot:分为STARTER与CORE的依赖关系职责之间的区别