@@ -3204,8 +3204,71 @@ def plot_engineering_2column(self) -> str: # noqa: C901, PLR0912, PLR0915
32043204 self .logger .info ("Saved engineering 2column plot to %s" , output_file )
32053205 return str (output_file )
32063206
3207+ def _plot_cbit_time_series (
3208+ self ,
3209+ ax : matplotlib .axes .Axes ,
3210+ times : pd .DatetimeIndex ,
3211+ cbit_vals : np .ndarray ,
3212+ ylabel : str ,
3213+ ) -> None :
3214+ ax .plot (times , cbit_vals , color = "tab:red" , linewidth = 1 , marker = "." , markersize = 3 )
3215+ ax .set_xlabel ("Time (UTC)" )
3216+ ax .set_ylabel (ylabel )
3217+ ax .set_title ("Ah Used vs. Time" )
3218+ ax .xaxis .set_major_formatter (matplotlib .dates .DateFormatter ("%Y-%m-%d\n %H:%M" ))
3219+ plt .setp (ax .get_xticklabels (), rotation = 0 , ha = "center" , fontsize = 8 )
3220+ ax .grid (visible = True , linestyle = "--" , alpha = 0.5 )
3221+
3222+ def _plot_cbit_distance (
3223+ self ,
3224+ ax : matplotlib .axes .Axes ,
3225+ distnav : xr .DataArray ,
3226+ cbit_at_nav : np .ndarray ,
3227+ ylabel : str ,
3228+ ) -> None :
3229+ dist_km = distnav .to_numpy () / 1000.0
3230+ inst_rate = np .gradient (cbit_at_nav , dist_km )
3231+
3232+ (line_ah ,) = ax .plot (
3233+ dist_km ,
3234+ cbit_at_nav ,
3235+ color = "tab:red" ,
3236+ linewidth = 1 ,
3237+ marker = "." ,
3238+ markersize = 3 ,
3239+ label = "Ah Used" ,
3240+ )
3241+ ax_rate = ax .twinx ()
3242+ (line_rate ,) = ax_rate .plot (
3243+ dist_km ,
3244+ inst_rate ,
3245+ color = "tab:blue" ,
3246+ linewidth = 0.8 ,
3247+ alpha = 0.6 ,
3248+ label = "Instantaneous rate (Ah/km)" ,
3249+ )
3250+ ax_rate .set_ylabel ("Instantaneous rate (Ah/km)" , color = "tab:blue" )
3251+ ax_rate .tick_params (axis = "y" , labelcolor = "tab:blue" )
3252+ last_rate = inst_rate [~ np .isnan (inst_rate )][- 1 ] if np .any (~ np .isnan (inst_rate )) else None
3253+ if last_rate is not None :
3254+ ax_rate .annotate (
3255+ f"{ last_rate :.3f} " ,
3256+ xy = (dist_km [- 1 ], last_rate ),
3257+ xytext = (4 , 0 ),
3258+ textcoords = "offset points" ,
3259+ color = "tab:blue" ,
3260+ fontsize = 8 ,
3261+ va = "center" ,
3262+ )
3263+ ax .set_xlabel ("Distance along track (km)" )
3264+ ax .set_ylabel (ylabel )
3265+ ax .set_title ("Ah Used vs. Distance" )
3266+ ax .grid (visible = True , axis = "x" , linestyle = "--" , alpha = 0.5 )
3267+ ax_rate .grid (visible = True , axis = "y" , linestyle = "--" , alpha = 0.5 )
3268+ ax .legend (handles = [line_ah , line_rate ], loc = "upper left" , fontsize = 8 )
3269+
32073270 def plot_cbit_2column (self ) -> str :
3208- """Create a 3 -panel plot for cbit_amphoursused: track map, distance scatter , time series."""
3271+ """Create a 4 -panel plot for cbit_amphoursused: track map, depth section , time series, distance .""" # noqa: E501
32093272 _CBIT_VAR = "cbit_amphoursused"
32103273
32113274 if "pytest" in sys .modules :
@@ -3236,11 +3299,15 @@ def plot_cbit_2column(self) -> str:
32363299 times = pd .to_datetime (cbit .coords ["time" ].to_numpy ())
32373300 cbit_vals = cbit .to_numpy ()
32383301
3239- fig = plt .figure (figsize = (18 , 8 ))
3240- gs = matplotlib .gridspec .GridSpec (2 , 2 , figure = fig , hspace = 0.35 , wspace = 0.15 )
3302+ fig = plt .figure (figsize = (18 , 11 ))
3303+ gs = matplotlib .gridspec .GridSpec (
3304+ 3 , 2 , figure = fig , hspace = 0.45 , wspace = 0.15 , height_ratios = [3 , 2 , 3 ]
3305+ )
3306+ fig .subplots_adjust (left = 0.06 )
32413307 ax_map = fig .add_subplot (gs [0 , 0 ])
32423308 ax_section = fig .add_subplot (gs [0 , 1 ])
32433309 ax_time = fig .add_subplot (gs [1 , :])
3310+ ax_dist = fig .add_subplot (gs [2 , :])
32443311
32453312 # Track map colored by Ah Used
32463313 self ._plot_track_map (
@@ -3272,13 +3339,8 @@ def plot_cbit_2column(self) -> str:
32723339 )
32733340 ax_section .set_xlabel ("Distance along track (km)" )
32743341
3275- # Time series
3276- ax_time .plot (times , cbit_vals , color = "tab:red" , linewidth = 1 , marker = "." , markersize = 3 )
3277- ax_time .set_xlabel ("Time (UTC)" )
3278- ax_time .set_ylabel (ylabel )
3279- ax_time .set_title ("Ah Used vs. Time" )
3280- ax_time .xaxis .set_major_formatter (matplotlib .dates .DateFormatter ("%Y-%m-%d\n %H:%M" ))
3281- plt .setp (ax_time .get_xticklabels (), rotation = 0 , ha = "center" , fontsize = 8 )
3342+ self ._plot_cbit_time_series (ax_time , times , cbit_vals , ylabel )
3343+ self ._plot_cbit_distance (ax_dist , distnav , cbit_at_nav , ylabel )
32823344
32833345 out_dir = (
32843346 self .output_dir
0 commit comments