77from fcutils .plotting .plot_elements import plot_line_outlined
88from fcutils .maths .utils import derivative
99
10- from proj .utils .misc import load_results_from_folder
10+ from proj .utils .misc import load_results_from_folder , duration_from_history
1111from proj .animation import variables_colors as colors
1212
1313
1414def _make_figure ():
15- f = plt .figure (figsize = (20 , 8 ))
15+ f = plt .figure (figsize = (20 , 12 ))
1616
17- gs = f .add_gridspec (2 , 8 )
17+ gs = f .add_gridspec (3 , 6 )
1818
19- xy_ax = f .add_subplot (gs [:, :2 ])
19+ xy_ax = f .add_subplot (gs [:2 , :2 ])
2020 xy_ax .axis ("equal" )
21- xy_ax .axis ("off" )
21+ # xy_ax.axis("off")
2222
2323 tau_ax = f .add_subplot (gs [0 , 2 :4 ])
24- sax = f .add_subplot (gs [1 , 2 : 4 ])
25- accel_ax = f .add_subplot (gs [0 , 4 :6 ])
26- cost_ax = f .add_subplot (gs [1 , 4 :6 ])
24+ sax = f .add_subplot (gs [2 , : 2 ]) # speed trajectory
25+ # accel_ax = f.add_subplot(gs[0, 4:6])
26+ # cost_ax = f.add_subplot(gs[1, 4:6])
2727
28- tau_int_ax = f .add_subplot (gs [0 , 6 :])
29- acc_int_ax = f .add_subplot (gs [1 , 6 :])
28+ tau_int_ax = f .add_subplot (gs [0 , 4 :6 ])
29+ omega_ax = f .add_subplot (gs [1 , 4 :6 ])
30+ speed_ax = f .add_subplot (gs [1 , 2 :4 ])
3031
31- return f , xy_ax , tau_ax , sax , accel_ax , cost_ax , tau_int_ax , acc_int_ax
32+ return f , xy_ax , tau_ax , sax , tau_int_ax , omega_ax , speed_ax
3233
3334
34- def _plot_xy (history , trajectory , plot_every , ax = None ):
35+ def _plot_xy (history , trajectory , plot_every , duration , ax = None ):
3536 # plot trajectory
3637 plot_line_outlined (
3738 ax ,
3839 trajectory [:, 0 ],
3940 trajectory [:, 1 ],
40- lw = 1 .5 ,
41+ lw = 2 .5 ,
4142 color = colors ["trajectory" ],
4243 outline = 0.5 ,
4344 outline_color = "white" ,
@@ -63,6 +64,9 @@ def _plot_xy(history, trajectory, plot_every, ax=None):
6364 outline_color = [0.2 , 0.2 , 0.2 ],
6465 )
6566
67+ # Set ax properties
68+ ax .set (xlabel = "cm" , ylabel = "cm" , title = f"Duration: { duration } s" )
69+
6670
6771def _plot_control (history , ax = None ):
6872 R , L = history ["tau_r" ], history ["tau_l" ]
@@ -85,6 +89,7 @@ def _plot_control(history, ax=None):
8589 solid_capstyle = "round" ,
8690 )
8791 ax .legend ()
92+ ax .set (xlabel = "# frames" , ylabel = "Force" , title = "Control history" )
8893
8994
9095def _plot_v (history , trajectory , plot_every , ax = None ):
@@ -108,6 +113,12 @@ def _plot_v(history, trajectory, plot_every, ax=None):
108113 history ["trajectory_idx" ], v , color = colors ["v" ], lw = 3 , zorder = 100 ,
109114 )
110115
116+ ax .set (
117+ xlabel = "Trajectory idx" ,
118+ ylabel = "Speed (cm/s)" ,
119+ title = "Speed trajectory" ,
120+ )
121+
111122
112123def _plot_accel (history , ax = None ):
113124 v , omega = history ["v" ], history ["omega" ]
@@ -134,7 +145,7 @@ def _plot_cost(cost_history, ax=None):
134145 ax .legend ()
135146
136147
137- def _plot_integrals (history , dt , tax = None , aax = None ):
148+ def _plot_integrals (history , dt , tax = None , oax = None , sax = None ):
138149 R , L = history ["nudot_right" ], history ["nudot_left" ]
139150
140151 plot_line_outlined (
@@ -153,54 +164,56 @@ def _plot_integrals(history, dt, tax=None, aax=None):
153164 lw = 2 ,
154165 solid_capstyle = "round" ,
155166 )
167+ tax .set (title = "Wheels accelerations" , xlabel = "# Frames" , ylabel = "accel" )
156168 tax .legend ()
157169
158170 # plot v and omega
159171 v , omega = history ["v" ], history ["omega" ]
160172
161173 plot_line_outlined (
162- aax ,
174+ sax ,
163175 v ,
164176 color = desaturate_color (colors ["v" ]),
165177 label = "$v$" ,
166178 lw = 2 ,
167179 solid_capstyle = "round" ,
168180 )
181+ sax .legend ()
182+ sax .set (title = "Running speed" , xlabel = "# frames" , ylabel = "$v$" )
183+
169184 plot_line_outlined (
170- aax ,
185+ oax ,
171186 omega ,
172187 color = desaturate_color (colors ["omega" ]),
173188 label = "$\\ omega$" ,
174189 lw = 2 ,
175190 solid_capstyle = "round" ,
176191 )
177- aax .legend ()
192+ oax .legend ()
193+ oax .set (title = "Angular velocity" , xlabel = "# frames" , ylabel = "$\\ omega$" )
178194
179195
180196def plot_results (results_folder , plot_every = 20 , save_path = None ):
181197 config , trajectory , history , cost_history = load_results_from_folder (
182198 results_folder
183199 )
200+ duration = duration_from_history (history , config )
184201
185- (
186- f ,
187- xy_ax ,
188- tau_ax ,
189- sax ,
190- accel_ax ,
191- cost_ax ,
192- tau_int_ax ,
193- acc_int_ax ,
194- ) = _make_figure ()
202+ f , xy_ax , tau_ax , sax , tau_int_ax , omega_ax , speed_ax = _make_figure ()
195203
196- _plot_xy (history , trajectory , plot_every , ax = xy_ax )
204+ _plot_xy (history , trajectory , plot_every , duration , ax = xy_ax )
197205 _plot_control (history , ax = tau_ax )
198- _plot_v (history , trajectory , plot_every , ax = sax )
199- _plot_accel (history , ax = accel_ax )
200- _plot_cost (cost_history , ax = cost_ax )
201- _plot_integrals (history , config ["dt" ], tax = tau_int_ax , aax = acc_int_ax )
206+ _plot_v (
207+ history , trajectory , plot_every , ax = sax
208+ ) # plot v against the trajectory
209+ # _plot_accel(history, ax=accel_ax)
210+ # _plot_cost(cost_history, ax=cost_ax)
211+ _plot_integrals (
212+ history , config ["dt" ], tax = tau_int_ax , oax = omega_ax , sax = speed_ax
213+ )
202214
203215 clean_axes (f )
216+ f .tight_layout ()
204217
205218 if save_path is not None :
206219 save_figure (f , str (save_path ))
0 commit comments