aalkaswan commited on
Commit
9acb7fe
·
verified ·
1 Parent(s): c41af96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -19,29 +19,43 @@ size_map = json.load(open("size_map.json"))
19
  raw_data = pd.read_csv("./tagged_data.csv")
20
 
21
  def plot_scatter(cat, x, y, col):
22
- if cat != "All":
23
- data = raw_data[raw_data["Category"] == cat]
24
- else:
25
- data = raw_data
26
- # Group and normalize the data
27
- grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
28
- grouped_cat["count"] = grouped_cat.groupby(["model"])["count"].transform(lambda x: x / x.sum())
29
 
30
- # Pivot the data for stacking
31
- pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0)
32
- # pivot_df = pivot_df.sort_values(by="A", ascending=False)
33
- # add color vis
34
  if col == "Size":
35
- pivot_df[col] = pivot_df.index.map(size_map)
36
- grouped_cat = grouped_cat.dropna(inplace=True)
37
  else:
38
- pivot_df[col] = pivot_df.index.str.split("/").str[0]
 
 
 
 
 
 
39
 
40
- # Create an interactive scatter plot
41
- fig = px.scatter(pivot_df, x=x, y=y, hover_name=pivot_df.index, title=f'{x} vs {y}', color=col, color_continuous_scale="agsunset")
 
 
 
 
 
42
 
43
- # Show the plot
44
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Tab 3
47
  def plot_scatter_tab3(subcat, col):
 
19
  raw_data = pd.read_csv("./tagged_data.csv")
20
 
21
  def plot_scatter(cat, x, y, col):
22
+ # minimal example
23
+ pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0).reset_index()
 
 
 
 
 
24
 
 
 
 
 
25
  if col == "Size":
26
+ pivot_df[col] = pivot_df["model"].map(size_map)
 
27
  else:
28
+ pivot_df[col] = pivot_df["model"].str.split("/").str[0]
29
+
30
+ fig = px.scatter_3d(pivot_df, x=x, y=y, z=z,
31
+ hover_name="model",
32
+ title=f'{x} vs {y} vs {z}',
33
+ color=col,
34
+ color_continuous_scale="agsunset")
35
 
36
+ # if cat != "All":
37
+ # data = raw_data[raw_data["Category"] == cat]
38
+ # else:
39
+ # data = raw_data
40
+ # # Group and normalize the data
41
+ # grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
42
+ # grouped_cat["count"] = grouped_cat.groupby(["model"])["count"].transform(lambda x: x / x.sum())
43
 
44
+ # # Pivot the data for stacking
45
+ # pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0)
46
+ # # pivot_df = pivot_df.sort_values(by="A", ascending=False)
47
+ # # add color vis
48
+ # if col == "Size":
49
+ # pivot_df[col] = pivot_df.index.map(size_map)
50
+ # grouped_cat = grouped_cat.dropna(inplace=True)
51
+ # else:
52
+ # pivot_df[col] = pivot_df.index.str.split("/").str[0]
53
+
54
+ # # Create an interactive scatter plot
55
+ # fig = px.scatter(pivot_df, x=x, y=y, hover_name=pivot_df.index, title=f'{x} vs {y}', color=col, color_continuous_scale="agsunset")
56
+
57
+ # # Show the plot
58
+ # return fig
59
 
60
  # Tab 3
61
  def plot_scatter_tab3(subcat, col):