【发布时间】:2020-12-02 13:51:44
【问题描述】:
我正在绘制一段时间内的值,以秒为单位。但是,我想在 x 轴上以分钟:秒为单位显示时间。我现在已经这样做了,但是我得到了像 0.8 这样的小数,你不需要时间符号。我尝试用'{}:{}.format(mins, secs)' 修复它,但后来我的 x 值变成了字符串,我无法再获得适当的 x 限制了。
有没有人知道一种将秒转换为 min:secs 同时又能保持相同 xlims 的好方法?
import matplotlib.pyplot as plt
y = np.random.rand(90, 1)
print(y)
x = np.arange(1380, 1470, 1) # seconds
x = x/60 # minutes
plt.plot(x, y)
plt.xlabel('Time (mins)')
【问题讨论】:
-
您是否尝试过转换为时间戳?我不确定 numpy,但 pandas 很容易处理,所以它在 numpy 中应该是相似的
标签: python numpy matplotlib time