99 - Horizontal dashed lines for θ_low and θ_high thresholds
1010
11112. figures/stage5_regime_transitions/regime_segmentation.png
12- - ΔΦ(t) curve over time
13- - Shaded regions for each regime (stable, pre-instability, instability, recovery)
14- - Vertical markers at each regime transition
12+ - Broad colored regime bands (stable / pre-instability / instability / recovery)
13+ - Clean vertical boundary lines at regime transitions
14+ - ΔΦ(t) overlaid as a single curve
1515
1616Reproducibility settings:
1717 seed = 0, DPI = 150, figure sizes as specified per figure below.
4747DPI = 150
4848np .random .seed (SEED )
4949
50- # ── Consistent regime colour palette ─────────────────────────────── ──────────
50+ # ── Consistent regime colour palette (Stage 2 / Stage 3 compatible) ──────────
5151REGIME_COLORS = {
5252 "stable" : "#2196F3" , # blue
5353 "pre-instability" : "#FF9800" , # orange
5454 "instability" : "#F44336" , # red
5555 "recovery" : "#4CAF50" , # green
5656}
57+ REGIME_ALPHA = 0.18
5758
5859# ── Paths ─────────────────────────────────────────────────────────────────────
5960_DATA_PATH = os .path .join (_REPO_ROOT , "data" , "synthetic" , "eic_timeseries.csv" )
@@ -125,46 +126,45 @@ def plot_regime_segmentation(
125126 regime_labels ,
126127 out_path : str ,
127128) -> None :
128- """Plot ΔΦ(t) with shaded regime regions and transition markers and save ."""
129+ """Plot broad regime bands with ΔΦ(t) overlaid and transition markers."""
129130 intervals = regime_shading_intervals (regime_labels )
130131 transitions = extract_transition_events (regime_labels )
131132
132133 fig , ax = plt .subplots (figsize = (14 , 5 ))
133134
134- # ── Shaded regime spans ───────────────────────────────────────────────────
135+ # ── Broad colored regime bands ────────────────────────────────────────────
136+ dt_half = (t [1 ] - t [0 ]) / 2
135137 for iv in intervals :
136138 t_start = t [iv .start ]
137- # Use half-step extension at the right edge to avoid gaps
138- t_end = t [iv .stop - 1 ] + (t [1 ] - t [0 ]) / 2 if iv .stop < len (t ) else t [- 1 ]
139+ t_end = t [iv .stop - 1 ] + dt_half if iv .stop < len (t ) else t [- 1 ] + dt_half
139140 ax .axvspan (
140141 t_start ,
141142 t_end ,
142- alpha = 0.18 ,
143+ alpha = REGIME_ALPHA ,
143144 color = REGIME_COLORS .get (iv .regime , "#CCCCCC" ),
144145 linewidth = 0 ,
145146 )
146147
147- # ── ΔΦ(t) curve ──────────────────────────────────────────────────────────
148+ # ── Clean boundary lines at transitions ──────────────────────────────────
149+ for ev in transitions :
150+ ax .axvline (
151+ t [ev .index ],
152+ color = "#616161" ,
153+ linewidth = 0.8 ,
154+ linestyle = "--" ,
155+ alpha = 0.6 ,
156+ zorder = 3 ,
157+ )
158+
159+ # ── ΔΦ(t) overlaid as a single curve ─────────────────────────────────────
148160 ax .plot (
149161 t , delta_phi ,
150162 color = "#212121" ,
151- linewidth = 0.9 ,
152- zorder = 3 ,
163+ linewidth = 1.0 ,
164+ zorder = 4 ,
153165 label = r"$\Delta\Phi(t)$" ,
154166 )
155167
156- # ── Transition markers ────────────────────────────────────────────────────
157- for ev in transitions :
158- x_trans = t [ev .index ]
159- ax .axvline (
160- x_trans ,
161- color = "#9C27B0" ,
162- linewidth = 0.9 ,
163- linestyle = ":" ,
164- alpha = 0.8 ,
165- zorder = 4 ,
166- )
167-
168168 ax .set_xlabel ("Time (s)" , fontsize = 11 )
169169 ax .set_ylabel (r"$\Delta\Phi(t)$" , fontsize = 11 )
170170 ax .set_title (
@@ -173,33 +173,35 @@ def plot_regime_segmentation(
173173 )
174174
175175 # ── Legend ────────────────────────────────────────────────────────────────
176+ present_regimes = set (regime_labels )
176177 regime_patches = [
177178 Patch (
178179 facecolor = REGIME_COLORS [r ],
179- alpha = 0.5 ,
180+ alpha = 0.6 ,
180181 label = r .capitalize (),
181182 )
182183 for r in ["stable" , "pre-instability" , "instability" , "recovery" ]
183- if r in set ( regime_labels )
184+ if r in present_regimes
184185 ]
185186 transition_handle = Line2D (
186187 [0 ], [0 ],
187- color = "#9C27B0 " ,
188- linewidth = 0.9 ,
189- linestyle = ": " ,
190- alpha = 0.8 ,
188+ color = "#616161 " ,
189+ linewidth = 0.8 ,
190+ linestyle = "-- " ,
191+ alpha = 0.6 ,
191192 label = "Transition" ,
192193 )
193194 delta_phi_handle = Line2D (
194195 [0 ], [0 ],
195196 color = "#212121" ,
196- linewidth = 0.9 ,
197+ linewidth = 1.0 ,
197198 label = r"$\Delta\Phi(t)$" ,
198199 )
199200 ax .legend (
200201 handles = [delta_phi_handle ] + regime_patches + [transition_handle ],
201202 loc = "upper right" ,
202203 fontsize = 8 ,
204+ framealpha = 0.9 ,
203205 )
204206 ax .grid (True , linestyle = "--" , linewidth = 0.4 , alpha = 0.4 )
205207
@@ -220,8 +222,8 @@ def main() -> None:
220222 # ── 2. Compute ΔΦ(t) ─────────────────────────────────────────────────────
221223 delta_phi = compute_delta_phi (series )
222224
223- # ── 3. Detect regimes ─────────────────────────────────────────────── ──────
224- regime_result = detect_regimes (delta_phi )
225+ # ── 3. Detect regimes with minimum dwell-time stability (10 samples) ──────
226+ regime_result = detect_regimes (delta_phi , min_dwell = 10 )
225227
226228 # ── 4. Plot ΔΦ(t) with threshold lines ───────────────────────────────────
227229 plot_delta_phi_thresholds (
0 commit comments