Spaces:
Running
Running
Anthony Liang commited on
Commit ·
610ba6d
1
Parent(s): c06b1ff
dark
Browse files- eval_viz_utils.py +29 -4
eval_viz_utils.py
CHANGED
|
@@ -20,6 +20,7 @@ logger = logging.getLogger(__name__)
|
|
| 20 |
PROGRESS_COLOR = "#B20000"
|
| 21 |
SUCCESS_COLOR = "#B20000"
|
| 22 |
THEME_LIGHT = {"facecolor": "white", "text_color": "black", "spine_color": "#333333"}
|
|
|
|
| 23 |
|
| 24 |
# Serif font (Palatino) for plots
|
| 25 |
plt.rcParams["font.family"] = "serif"
|
|
@@ -27,6 +28,30 @@ plt.rcParams["font.serif"] = ["Palatino", "Palatino Linotype", "DejaVu Serif", "
|
|
| 27 |
plt.rcParams["font.size"] = 11
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def create_combined_progress_success_plot(
|
| 31 |
progress_pred: np.ndarray,
|
| 32 |
num_frames: int,
|
|
@@ -76,7 +101,7 @@ def create_combined_progress_success_plot(
|
|
| 76 |
ax.plot(progress_pred, linewidth=2)
|
| 77 |
ax.set_ylabel("Progress")
|
| 78 |
|
| 79 |
-
# Build title
|
| 80 |
if title is None:
|
| 81 |
title_parts = ["Progress"]
|
| 82 |
if loss is not None:
|
|
@@ -84,7 +109,7 @@ def create_combined_progress_success_plot(
|
|
| 84 |
if pearson is not None:
|
| 85 |
title_parts.append(f"Pearson: {pearson:.2f}")
|
| 86 |
title = ", ".join(title_parts)
|
| 87 |
-
fig.suptitle(title)
|
| 88 |
|
| 89 |
# Set y-limits and ticks (always continuous since discrete is converted before this function)
|
| 90 |
ax.set_ylim(0, 1)
|
|
@@ -355,9 +380,9 @@ def create_progress_success_gif(
|
|
| 355 |
head_dots.append(head_dot)
|
| 356 |
|
| 357 |
if title and str(title).strip():
|
| 358 |
-
# Place title inside figure top margin
|
| 359 |
fig.suptitle(
|
| 360 |
-
str(title).strip(),
|
| 361 |
fontsize=12,
|
| 362 |
fontweight="bold",
|
| 363 |
color=theme["text_color"],
|
|
|
|
| 20 |
PROGRESS_COLOR = "#B20000"
|
| 21 |
SUCCESS_COLOR = "#B20000"
|
| 22 |
THEME_LIGHT = {"facecolor": "white", "text_color": "black", "spine_color": "#333333"}
|
| 23 |
+
THEME_DARK = {"facecolor": "black", "text_color": "white", "spine_color": "#444444"}
|
| 24 |
|
| 25 |
# Serif font (Palatino) for plots
|
| 26 |
plt.rcParams["font.family"] = "serif"
|
|
|
|
| 28 |
plt.rcParams["font.size"] = 11
|
| 29 |
|
| 30 |
|
| 31 |
+
def wrap_title(text: str, max_chars_per_line: int = 48) -> str:
|
| 32 |
+
"""Wrap a long title onto at most two lines, breaking at word boundaries."""
|
| 33 |
+
if not text or not str(text).strip():
|
| 34 |
+
return text
|
| 35 |
+
text = str(text).strip()
|
| 36 |
+
if len(text) <= max_chars_per_line:
|
| 37 |
+
return text
|
| 38 |
+
words = text.split()
|
| 39 |
+
line1, line2 = [], []
|
| 40 |
+
line1_len = 0
|
| 41 |
+
for w in words:
|
| 42 |
+
need = len(w) + (1 if line1 else 0) # space before if not first
|
| 43 |
+
if line2:
|
| 44 |
+
line2.append(w)
|
| 45 |
+
elif line1_len + need <= max_chars_per_line:
|
| 46 |
+
line1.append(w)
|
| 47 |
+
line1_len += need
|
| 48 |
+
else:
|
| 49 |
+
line2.append(w)
|
| 50 |
+
if not line2:
|
| 51 |
+
return text
|
| 52 |
+
return " ".join(line1) + "\n" + " ".join(line2)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
def create_combined_progress_success_plot(
|
| 56 |
progress_pred: np.ndarray,
|
| 57 |
num_frames: int,
|
|
|
|
| 101 |
ax.plot(progress_pred, linewidth=2)
|
| 102 |
ax.set_ylabel("Progress")
|
| 103 |
|
| 104 |
+
# Build title (wrap long task text onto two lines)
|
| 105 |
if title is None:
|
| 106 |
title_parts = ["Progress"]
|
| 107 |
if loss is not None:
|
|
|
|
| 109 |
if pearson is not None:
|
| 110 |
title_parts.append(f"Pearson: {pearson:.2f}")
|
| 111 |
title = ", ".join(title_parts)
|
| 112 |
+
fig.suptitle(wrap_title(title))
|
| 113 |
|
| 114 |
# Set y-limits and ticks (always continuous since discrete is converted before this function)
|
| 115 |
ax.set_ylim(0, 1)
|
|
|
|
| 380 |
head_dots.append(head_dot)
|
| 381 |
|
| 382 |
if title and str(title).strip():
|
| 383 |
+
# Place title inside figure top margin; wrap long task text onto two lines
|
| 384 |
fig.suptitle(
|
| 385 |
+
wrap_title(str(title).strip()),
|
| 386 |
fontsize=12,
|
| 387 |
fontweight="bold",
|
| 388 |
color=theme["text_color"],
|