python-3.x - python : Time format into Decimal

标签 python-3.x

如何在Python中将HH:MM:SS.SSS格式的时间转换为十进制数?示例:我想将时间“00:00:26.94”转换为十进制数,以便我可以使用十进制数作为数据来绘制图表。

最佳答案

您可以使用plt.plot_date()mdates.date2num() 结合.

import datetime as dt
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 

d = dt.datetime.strptime("00:00:26.94","%H:%M:%S.%f")
plt.plot_date(mdates.date2num(d),1)
plt.gca().set_xlim((dt.datetime.strptime("00:00:25","%H:%M:%S"),
                    dt.datetime.strptime("00:00:27","%H:%M:%S")))
plt.show() 

示例图: enter image description here

关于python-3.x - python : Time format into Decimal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60386121/

相关文章:

python - 在 BeautifulSoup 中处理 "next_sibling"时遇到问题

python - pywhatkit.sendwhatmsg_to_group 不工作

python-3.x - 我需要编写一个程序来计算一个人使用机器的小时数,但我不能超过 23 :59:59

python - 如何在Python中按字典键的嵌套列表进行分组

python - 将日期范围拆分为多个范围

python - 使用 Python 3 将多个 matplotlib 图形放入 Excel 中

python - 为什么在奇异容器中安装主目录会破坏 python 导入?

python - 自动编码器最后一层的 Keras 尺寸不匹配

python-3.x - 使用 tkinter.filedialog 时为 "libpng warning: iCCP: known incorrect sRGB profile"

python - 在装饰器内部使用部分时 self 丢失