当每个新零件都基于其“加载”或“执行”等功能创建时,我想绘制垂直线。因此,我有一列名为“ new_part”的列,它指示是否创建了新零件,并用它提取每个新零件的时间戳(当new_part == 1时)。
FV(Future Value)
以下没有问题的情节
parts_time = fn_04_num[fn_04_num['new_part'] == 1]['Timestamp']
parts_time = pd.to_datetime(parts_time, format="%Y-%m-%d %H:%M:%S")
但是一旦添加此循环以获取垂直线,就会出现此错误
fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.set_xlabel('Time')
ax1.set_ylabel('Aload', color=color)
ax1.plot(fn_04_num['Timestamp'], fn_04_num['Aload'], color=color)
ax1.tick_params(axis='y', labelcolor=color)
# instantiate a second axes that shares the same x-axis
ax2 = ax1.twinx()
color = 'tab:blue'
ax2.set_ylabel('Status',
color=color)
ax2.hlines(y=fn_04_num['execution'],
xmin=fn_04_num['Timestamp'],
xmax=fn_04_num['Timestamp2'],
color=color)
ax2.tick_params(axis='y',
labelcolor=color)
ax3 = ax1.twinx()
for time in parts_time:
color = 'tab:black'
ax3.axvline(x=time)
# Right y-label is slightly clipped
fig.tight_layout()
plt.show()
我验证了我的数据类型(时间戳与part_time的格式相同),所以我真的不明白我在做什么错。
感谢您的帮助!