【发布时间】:2020-04-03 05:09:02
【问题描述】:
我无法对作业完成时间(Y 轴)进行排序。目前它正在显示每个 Y 轴的内容。将来我会添加更多的 Y 轴。
有没有办法对 Y 轴值进行排序?我的示例代码粘贴在下面,并附上了问题的屏幕截图。 Screenshot attached
from matplotlib import pyplot as plt
from matplotlib.dates import DateFormatter
import datetime as DT
xaxis =[ \[][1]
DT.datetime(2020, 3, 19, 0, 0),
DT.datetime(2020, 3, 20, 0, 0),
DT.datetime(2020, 3, 23, 0, 0),
DT.datetime(2020, 3, 24, 0, 0)
]
jobrunt1 = [DT.datetime(2020, 3, 20, 6, 39, 0),
DT.datetime(2020, 3, 23, 15, 59, 24),
DT.datetime(2020, 3, 24, 6, 37, 4),
DT.datetime(2020, 3, 25, 6, 38, 0)]
jobrunt2 = [DT.datetime(2020, 3, 20, 8, 40, 0),
DT.datetime(2020, 3, 23, 18, 19, 24),
DT.datetime(2020, 3, 24, 4, 39, 4),
DT.datetime(2020, 3, 25, 1, 20, 8)]
yaxis1 = [DT.datetime.strftime(y, "%H:%M") for y in jobrunt1]
yaxis2 = [DT.datetime.strftime(z, "%H:%M") for z in jobrunt2]
f, ax = plt.subplots(figsize=(12, 4))
ax.xaxis.set_major_formatter(DateFormatter('%d/%m/%Y'))
ax.yaxis.set_minor_formatter(DateFormatter('%H:%M'))
ax.set_xlabel('Rundt')
ax.set_ylabel('Job Finish Time')
ax.plot(xaxis, yaxis1, marker='o', label='Job1')
ax.plot(xaxis, yaxis2, marker='^', label='Job2')
plt.show()
谢谢
【问题讨论】:
标签: python pandas matplotlib