Spaces:
Running
Running
Commit
·
5be3cef
1
Parent(s):
d6283a9
Segment Subsets by Color and Resize Data Points
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from bokeh.plotting import figure
|
4 |
from bokeh.models import ColumnDataSource, HoverTool
|
|
|
|
|
5 |
|
6 |
# --- Define Styles ---
|
7 |
st.markdown(
|
@@ -46,6 +48,10 @@ source = ColumnDataSource(data=dict(
|
|
46 |
img=df['img']
|
47 |
))
|
48 |
|
|
|
|
|
|
|
|
|
49 |
# Configure figure
|
50 |
TOOLTIPS = """
|
51 |
<div>
|
@@ -60,6 +66,6 @@ TOOLTIPS = """
|
|
60 |
|
61 |
|
62 |
p = figure(width=400, height=400, tooltips=TOOLTIPS, title="")
|
63 |
-
p.scatter('x', 'y', size=
|
64 |
|
65 |
st.bokeh_chart(p)
|
|
|
2 |
import pandas as pd
|
3 |
from bokeh.plotting import figure
|
4 |
from bokeh.models import ColumnDataSource, HoverTool
|
5 |
+
from bokeh.palettes import Category10
|
6 |
+
from bokeh.transform import factor_cmap
|
7 |
|
8 |
# --- Define Styles ---
|
9 |
st.markdown(
|
|
|
48 |
img=df['img']
|
49 |
))
|
50 |
|
51 |
+
unique_labels = df['label'].unique().tolist()
|
52 |
+
palette = Category10[len(unique_labels)] if len(unique_labels) <= 10 else Category10[10]
|
53 |
+
|
54 |
+
|
55 |
# Configure figure
|
56 |
TOOLTIPS = """
|
57 |
<div>
|
|
|
66 |
|
67 |
|
68 |
p = figure(width=400, height=400, tooltips=TOOLTIPS, title="")
|
69 |
+
p.scatter('x', 'y', size=8, source=source, color=factor_cmap('label', palette=palette, factors=unique_labels))
|
70 |
|
71 |
st.bokeh_chart(p)
|