Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -441,29 +441,28 @@ def cross_plot_static(actual, pred):
|
|
| 441 |
return fig
|
| 442 |
|
| 443 |
# =========================
|
| 444 |
-
# Track plot (Plotly)
|
| 445 |
# =========================
|
| 446 |
def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
|
| 447 |
-
#
|
| 448 |
def _col_1d(frame: pd.DataFrame, col: str) -> pd.Series:
|
| 449 |
if col not in frame.columns:
|
| 450 |
return pd.Series(dtype=float)
|
| 451 |
v = frame[col]
|
| 452 |
-
if isinstance(v, pd.DataFrame):
|
| 453 |
v = v.iloc[:, 0]
|
| 454 |
return pd.Series(v, dtype=float)
|
| 455 |
|
|
|
|
| 456 |
depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
|
| 457 |
if depth_col is not None:
|
| 458 |
y = pd.Series(df[depth_col]).astype(float)
|
| 459 |
ylab = depth_col
|
| 460 |
-
y_range = [float(y.max()), float(y.min())] # reverse for logs
|
| 461 |
else:
|
| 462 |
-
y = pd.Series(np.arange(1, len(df) + 1))
|
| 463 |
ylab = "Point Index"
|
| 464 |
-
y_range = [float(y.max()), float(y.min())]
|
| 465 |
|
| 466 |
-
# X (GR)
|
| 467 |
x_pred = _col_1d(df, pred_col)
|
| 468 |
if include_actual and actual_col in df.columns:
|
| 469 |
x_act = _col_1d(df, actual_col)
|
|
@@ -512,16 +511,19 @@ def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
|
|
| 512 |
showline=True, linewidth=1.2, linecolor="#444", mirror=True,
|
| 513 |
showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
|
| 514 |
)
|
|
|
|
| 515 |
fig.update_yaxes(
|
| 516 |
-
title_text=
|
| 517 |
title_font=dict(size=20, family=BOLD_FONT, color="#000"),
|
| 518 |
tickfont=dict(size=15, family=BOLD_FONT, color="#000"),
|
| 519 |
-
|
|
|
|
| 520 |
showline=True, linewidth=1.2, linecolor="#444", mirror=True,
|
| 521 |
showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
|
| 522 |
)
|
| 523 |
return fig
|
| 524 |
|
|
|
|
| 525 |
# ---------- Preview modal (matplotlib) ----------
|
| 526 |
def preview_tracks(df: pd.DataFrame, cols: list[str]):
|
| 527 |
cols = [c for c in cols if c in df.columns]
|
|
|
|
| 441 |
return fig
|
| 442 |
|
| 443 |
# =========================
|
| 444 |
+
# Track plot (Plotly) — y-axis reversed
|
| 445 |
# =========================
|
| 446 |
def track_plot(df, include_actual=True, pred_col="GR_Pred", actual_col="GR"):
|
| 447 |
+
# ensure 1D series even if duplicate col names exist
|
| 448 |
def _col_1d(frame: pd.DataFrame, col: str) -> pd.Series:
|
| 449 |
if col not in frame.columns:
|
| 450 |
return pd.Series(dtype=float)
|
| 451 |
v = frame[col]
|
| 452 |
+
if isinstance(v, pd.DataFrame):
|
| 453 |
v = v.iloc[:, 0]
|
| 454 |
return pd.Series(v, dtype=float)
|
| 455 |
|
| 456 |
+
# Depth (or index) for y
|
| 457 |
depth_col = next((c for c in df.columns if 'depth' in str(c).lower()), None)
|
| 458 |
if depth_col is not None:
|
| 459 |
y = pd.Series(df[depth_col]).astype(float)
|
| 460 |
ylab = depth_col
|
|
|
|
| 461 |
else:
|
| 462 |
+
y = pd.Series(np.arange(1, len(df) + 1), dtype=float)
|
| 463 |
ylab = "Point Index"
|
|
|
|
| 464 |
|
| 465 |
+
# X (GR) domain and ticks
|
| 466 |
x_pred = _col_1d(df, pred_col)
|
| 467 |
if include_actual and actual_col in df.columns:
|
| 468 |
x_act = _col_1d(df, actual_col)
|
|
|
|
| 511 |
showline=True, linewidth=1.2, linecolor="#444", mirror=True,
|
| 512 |
showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
|
| 513 |
)
|
| 514 |
+
# The key change: reverse y-axis universally
|
| 515 |
fig.update_yaxes(
|
| 516 |
+
title_text=ylab,
|
| 517 |
title_font=dict(size=20, family=BOLD_FONT, color="#000"),
|
| 518 |
tickfont=dict(size=15, family=BOLD_FONT, color="#000"),
|
| 519 |
+
autorange="reversed", # <-- ensures top=shallow, bottom=deep
|
| 520 |
+
ticks="outside",
|
| 521 |
showline=True, linewidth=1.2, linecolor="#444", mirror=True,
|
| 522 |
showgrid=True, gridcolor="rgba(0,0,0,0.12)", automargin=True
|
| 523 |
)
|
| 524 |
return fig
|
| 525 |
|
| 526 |
+
|
| 527 |
# ---------- Preview modal (matplotlib) ----------
|
| 528 |
def preview_tracks(df: pd.DataFrame, cols: list[str]):
|
| 529 |
cols = [c for c in cols if c in df.columns]
|