2 """Plot wheel angle and speed of the scenario.
6 ./sp_and_wa_plot.py some-generated-file.traj.json
9 from matplotlib import pyplot as plt
14 def ticks_to_seconds(t):
15 return t * 0.02 # one tick is 20 ms
26 if __name__ == "__main__":
27 if len(sys.argv) != 2:
31 with open(f"{sys.argv[1]}", "r") as f:
35 plt.rc('axes', unicode_minus=False)
38 ax = fig.add_subplot(111)
39 ax.set_title("Wheel Angle and Speed in time")
40 ax.set_xlabel("Time [s]")
41 ax.set_ylabel("Wheel Angle [deg]")
44 ax2.set_ylabel("Speed [kmph]")
46 t = [ticks_to_seconds(i) for i in range(len(plan["traj"]))]
47 wa = [rad_to_deg(t[3]) for t in plan["traj"]]
48 sp = [mps_to_kmph(t[4]) for t in plan["traj"]]
49 fwd = [t[6]*0.2-0.1 for t in plan["traj"]]
51 p1 = ax.plot(t, wa, 'b-', label="Wheel Angle [deg]")
52 p2 = ax2.plot(t, sp, 'r-', label="Speed [kmph]")
53 p3 = ax2.plot(t, fwd, 'g-', label="Gear")
55 # Center both Y-axes at zero
56 yabs_max = abs(max(ax.get_ylim(), key=abs))
57 ax.set_ylim(ymin=-yabs_max, ymax=yabs_max)
58 yabs_max = abs(max(ax2.get_ylim(), key=abs))
59 ax2.set_ylim(ymin=-yabs_max, ymax=yabs_max)
62 labs = [l.get_label() for l in lns]
63 ax.legend(lns, labs, loc=0)
64 ax.grid(True, "both", linestyle=":", color="tab:gray")
66 plt.savefig(sys.argv[1] + "-vals.pdf", bbox_inches="tight")
67 plt.savefig(sys.argv[1] + "-vals.png", bbox_inches="tight")