wi-lab commited on
Commit
d5edc0f
·
1 Parent(s): 2669c00

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -22,6 +22,9 @@ 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,20 +128,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
- fig = px.scatter(
130
- filtered_df,
131
- x='x',
132
- y='y',
133
- color=color_by,
134
- hover_data=['tech', 'snr', 'mod', 'mob'],
 
 
 
 
 
 
 
 
 
135
  title=f"t-SNE of {representation} ({len(filtered_df)} samples)",
136
- template="plotly_white"
 
 
137
  )
138
- fig.update_layout(legend_title_text=color_by.capitalize())
139
- fig.update_traces(mode='markers', marker=dict(size=6, opacity=0.8, line=dict(width=0)))
140
- fig.update_xaxes(range=[x_min - x_pad, x_max + x_pad])
141
- fig.update_yaxes(range=[y_min - y_pad, y_max + y_pad])
142
 
143
  coord_info = f"x[{x_min:.3f},{x_max:.3f}] y[{y_min:.3f},{y_max:.3f}]"
144
  return fig, f"{status_msg} | filtered samples: {len(filtered_df)} | {coord_info}"
 
22
  from sklearn.manifold import TSNE
23
  from sklearn.decomposition import PCA
24
  import plotly.express as px
25
+ import plotly.graph_objects as go
26
+ import itertools
27
+ from plotly.colors import qualitative
28
 
29
  # Load data
30
  def load_data():
 
128
  x_pad = max(1e-3, (x_max - x_min) * 0.05)
129
  y_pad = max(1e-3, (y_max - y_min) * 0.05)
130
 
131
+ # Plot (explicit Scattergl to ensure points render)
132
+ palette = itertools.cycle(qualitative.Set2 + qualitative.Set3 + qualitative.D3)
133
+ fig = go.Figure()
134
+ for cls in sorted(filtered_df[color_by].unique()):
135
+ mask = filtered_df[color_by] == cls
136
+ color = next(palette)
137
+ fig.add_trace(go.Scattergl(
138
+ x=filtered_df.loc[mask, 'x'],
139
+ y=filtered_df.loc[mask, 'y'],
140
+ mode='markers',
141
+ name=str(cls),
142
+ marker=dict(size=6, opacity=0.8, color=color, line=dict(width=0)),
143
+ hovertext=filtered_df.loc[mask, ['tech', 'snr', 'mod', 'mob']].astype(str).agg('<br>'.join, axis=1),
144
+ hoverinfo='text'
145
+ ))
146
+ fig.update_layout(
147
  title=f"t-SNE of {representation} ({len(filtered_df)} samples)",
148
+ template="plotly_white",
149
+ legend_title_text=color_by.capitalize(),
150
+ margin=dict(l=40, r=20, t=60, b=40),
151
  )
152
+ fig.update_xaxes(range=[x_min - x_pad, x_max + x_pad], zeroline=False)
153
+ fig.update_yaxes(range=[y_min - y_pad, y_max + y_pad], zeroline=False)
 
 
154
 
155
  coord_info = f"x[{x_min:.3f},{x_max:.3f}] y[{y_min:.3f},{y_max:.3f}]"
156
  return fig, f"{status_msg} | filtered samples: {len(filtered_df)} | {coord_info}"