Xiaodong's picture
upload
ab45969
import json
import matplotlib.pyplot as plt
# 读取JSON文件
with open('action_val.json', 'r') as file:
data = json.load(file)
# 提取数据
scene_data = data[1]
action_pred = scene_data["action_pred"]
action_gt = scene_data["action_gt"]
# 提取转向角和速度
pred_steering_angles = [a[0] for a in action_pred]
pred_speeds = [a[1] for a in action_pred]
gt_steering_angles = [a[0] for a in action_gt]
gt_speeds = [a[1] for a in action_gt]
# 绘图
plt.figure(figsize=(12, 5))
# 转向角的 plot
plt.subplot(1, 2, 1)
plt.plot(pred_steering_angles, label='Predicted Steering Angle', color='blue', marker='o')
plt.plot(gt_steering_angles, label='Ground Truth Steering Angle', color='orange', marker='o')
plt.title("Steering Angle")
plt.xlabel("Time Step")
plt.ylabel("Angle")
plt.legend()
# 速度的 plot
plt.subplot(1, 2, 2)
plt.plot(pred_speeds, label='Predicted Speed', color='blue', marker='o')
plt.plot(gt_speeds, label='Ground Truth Speed', color='orange', marker='o')
plt.title("Speed")
plt.xlabel("Time Step")
plt.ylabel("Speed")
plt.legend()
plt.tight_layout()
plt.savefig('val.jpg')