wi-lab commited on
Commit
8ecde60
·
1 Parent(s): 62da1db

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +24 -21
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 plotly.express as px
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 (force serialization-friendly types)
129
- plot_df = filtered_df.copy()
130
- plot_df['x'] = plot_df['x'].astype(float)
131
- plot_df['y'] = plot_df['y'].astype(float)
132
-
133
- fig = px.scatter(
134
- plot_df,
135
- x='x',
136
- y='y',
137
- color=color_by,
138
- hover_data=['tech', 'snr', 'mod', 'mob'],
139
- title=f"t-SNE of {representation} ({len(filtered_df)} samples)",
140
- template="plotly_white",
141
- render_mode="auto",
142
- color_discrete_sequence=px.colors.qualitative.Set2 + px.colors.qualitative.Set3,
143
- )
144
- fig.update_layout(legend_title_text=color_by.capitalize(), margin=dict(l=40, r=20, t=60, b=40))
145
- fig.update_traces(mode='markers', marker=dict(size=8, opacity=0.9, line=dict(width=0)))
146
- fig.update_xaxes(range=[x_min - x_pad, x_max + x_pad], zeroline=False)
147
- fig.update_yaxes(range=[y_min - y_pad, y_max + y_pad], zeroline=False)
 
 
 
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)}"