UCS2014 commited on
Commit
fdd615a
·
verified ·
1 Parent(s): 4aff221

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
app.py CHANGED
@@ -520,13 +520,10 @@ def track_plot(df, include_actual=True):
520
  )
521
  return fig
522
 
523
- # ---------- Preview modal (matplotlib) ----------
524
- # ---------- Preview modal (matplotlib) ----------
525
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
526
  """
527
  Render quick-look tracks for the selected columns with DISTINCT colors per input,
528
- instead of the previous single black line. Colors are stable across sessions
529
- (ordered by column index) using matplotlib's 'tab20' palette.
530
  """
531
  cols = [c for c in cols if c in df.columns]
532
  n = len(cols)
@@ -536,12 +533,7 @@ def preview_tracks(df: pd.DataFrame, cols: list[str]):
536
  ax.axis("off")
537
  return fig
538
 
539
- # one row, n columns; share Y so depth/index aligns
540
- fig, axes = plt.subplots(1, n, figsize=(2.2 * n, 7.0), sharey=True, dpi=100)
541
- if n == 1:
542
- axes = [axes]
543
-
544
- # Determine vertical axis (Depth if present, else point index)
545
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
546
  if depth_col is not None:
547
  idx = pd.to_numeric(df[depth_col], errors="coerce")
@@ -550,23 +542,33 @@ def preview_tracks(df: pd.DataFrame, cols: list[str]):
550
  idx = pd.Series(np.arange(1, len(df) + 1))
551
  y_label = "Point Index"
552
 
553
- # Build a stable color map for the selected columns
554
- cmap = plt.get_cmap("tab20") # 20 distinct hues; cycles if >20 inputs
 
 
 
 
 
 
 
555
  col_colors = {col: cmap(i % cmap.N) for i, col in enumerate(cols)}
556
 
557
- # Plot each selected feature with its own color
558
- for ax, col in zip(axes, cols):
559
  x = pd.to_numeric(df[col], errors="coerce")
560
  ax.plot(x, idx, '-', lw=1.6, color=col_colors[col])
561
  ax.set_xlabel(col)
562
  ax.xaxis.set_label_position('top')
563
  ax.xaxis.tick_top()
564
- ax.invert_yaxis()
565
  ax.grid(True, linestyle=":", alpha=0.3)
566
- for s in ax.spines.values():
567
- s.set_visible(True)
568
 
569
- axes[0].set_ylabel(y_label)
 
 
 
 
 
 
570
  fig.tight_layout()
571
  return fig
572
 
 
520
  )
521
  return fig
522
 
 
 
523
  def preview_tracks(df: pd.DataFrame, cols: list[str]):
524
  """
525
  Render quick-look tracks for the selected columns with DISTINCT colors per input,
526
+ and reserve the Y-axis across all plots so depth/index is aligned.
 
527
  """
528
  cols = [c for c in cols if c in df.columns]
529
  n = len(cols)
 
533
  ax.axis("off")
534
  return fig
535
 
536
+ # Depth or fallback to point index
 
 
 
 
 
537
  depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
538
  if depth_col is not None:
539
  idx = pd.to_numeric(df[depth_col], errors="coerce")
 
542
  idx = pd.Series(np.arange(1, len(df) + 1))
543
  y_label = "Point Index"
544
 
545
+ # Y range is reserved across all subplots
546
+ y_min, y_max = float(idx.min()), float(idx.max())
547
+
548
+ fig, axes = plt.subplots(1, n, figsize=(2.2 * n, 7.0), sharey=True, dpi=100)
549
+ if n == 1:
550
+ axes = [axes]
551
+
552
+ # Stable color palette
553
+ cmap = plt.get_cmap("tab20")
554
  col_colors = {col: cmap(i % cmap.N) for i, col in enumerate(cols)}
555
 
556
+ for i, (ax, col) in enumerate(zip(axes, cols)):
 
557
  x = pd.to_numeric(df[col], errors="coerce")
558
  ax.plot(x, idx, '-', lw=1.6, color=col_colors[col])
559
  ax.set_xlabel(col)
560
  ax.xaxis.set_label_position('top')
561
  ax.xaxis.tick_top()
562
+ ax.set_ylim(y_max, y_min) # reserve and invert depth axis
563
  ax.grid(True, linestyle=":", alpha=0.3)
 
 
564
 
565
+ # Only show y-axis label + ticks on the first subplot
566
+ if i == 0:
567
+ ax.set_ylabel(y_label)
568
+ else:
569
+ ax.tick_params(labelleft=False)
570
+ ax.set_ylabel("")
571
+
572
  fig.tight_layout()
573
  return fig
574