Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ import numpy as np
|
|
| 21 |
import pandas as pd
|
| 22 |
from sklearn.manifold import TSNE
|
| 23 |
from sklearn.decomposition import PCA
|
| 24 |
-
import
|
| 25 |
|
| 26 |
# Load data
|
| 27 |
def load_data():
|
|
@@ -125,26 +125,29 @@ def plot_tsne(tech_filter, snr_filter, mod_filter, mob_filter, representation, c
|
|
| 125 |
x_pad = max(1e-3, (x_max - x_min) * 0.05)
|
| 126 |
y_pad = max(1e-3, (y_max - y_min) * 0.05)
|
| 127 |
|
| 128 |
-
# Plot
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
coord_info = f"x[{x_min:.3f},{x_max:.3f}] y[{y_min:.3f},{y_max:.3f}]"
|
| 150 |
trace_info = f"traces: {len(fig.data)}"
|
|
|
|
| 21 |
import pandas as pd
|
| 22 |
from sklearn.manifold import TSNE
|
| 23 |
from sklearn.decomposition import PCA
|
| 24 |
+
import matplotlib.pyplot as plt
|
| 25 |
|
| 26 |
# Load data
|
| 27 |
def load_data():
|
|
|
|
| 125 |
x_pad = max(1e-3, (x_max - x_min) * 0.05)
|
| 126 |
y_pad = max(1e-3, (y_max - y_min) * 0.05)
|
| 127 |
|
| 128 |
+
# Plot using matplotlib for maximum reliability in Spaces
|
| 129 |
+
fig, ax = plt.subplots(figsize=(7, 6))
|
| 130 |
+
# cycle through a tab20 palette
|
| 131 |
+
colors = plt.cm.tab20(np.linspace(0, 1, len(filtered_df[color_by].unique())))
|
| 132 |
+
for c, cls in zip(colors, sorted(filtered_df[color_by].unique())):
|
| 133 |
+
mask = filtered_df[color_by] == cls
|
| 134 |
+
ax.scatter(
|
| 135 |
+
filtered_df.loc[mask, 'x'],
|
| 136 |
+
filtered_df.loc[mask, 'y'],
|
| 137 |
+
s=18,
|
| 138 |
+
alpha=0.8,
|
| 139 |
+
label=str(cls),
|
| 140 |
+
color=c,
|
| 141 |
+
edgecolors='none',
|
| 142 |
+
)
|
| 143 |
+
ax.set_xlim(x_min - x_pad, x_max + x_pad)
|
| 144 |
+
ax.set_ylim(y_min - y_pad, y_max + y_pad)
|
| 145 |
+
ax.set_xlabel("t-SNE x")
|
| 146 |
+
ax.set_ylabel("t-SNE y")
|
| 147 |
+
ax.set_title(f"t-SNE of {representation} ({len(filtered_df)} samples)")
|
| 148 |
+
ax.grid(True, alpha=0.3)
|
| 149 |
+
ax.legend(title=color_by, fontsize=9, title_fontsize=10, loc='best')
|
| 150 |
+
fig.tight_layout()
|
| 151 |
|
| 152 |
coord_info = f"x[{x_min:.3f},{x_max:.3f}] y[{y_min:.3f},{y_max:.3f}]"
|
| 153 |
trace_info = f"traces: {len(fig.data)}"
|