marcgauch 2023-06-03 13:13:03 +02:00
parent 96a26a8ea0
commit a4c16662db
2 changed files with 46 additions and 6 deletions

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}

View File

@ -21,10 +21,21 @@ df = pd.DataFrame(
) )
# define cluster colors # define cluster colors
# https://loading.io/color/feature/Spectral-10/
COLORS = {
"0": "#9e0142",
"1": "#d53e4f",
"2": "#f46d43",
"3": "#fdae61",
"4": "#fee08b",
"5": "#e6f598",
"6": "#abdda4",
"7": "#66c2a5",
"8": "#3288bd",
"9": "#5e4fa2",
}
COLORS = {"0": "red", "1": "blue", "2": "grey"} X, y = make_blobs(n_samples=300, centers=3, n_features=2, random_state=0)
X, y = make_blobs(n_samples=100, centers=3, n_features=2, random_state=0)
cluster_df = pd.DataFrame(data=X, columns=["X", "Y"]) cluster_df = pd.DataFrame(data=X, columns=["X", "Y"])
cluster_df["cluster"] = [str(i) for i in y] cluster_df["cluster"] = [str(i) for i in y]
@ -97,6 +108,21 @@ app.layout = html.Div(
children=[ children=[
html.Div( html.Div(
[ [
dbc.Row(
[
dbc.Col(
[
dcc.Slider(
1,
10,
1,
value=3,
id="slider_1",
)
]
),
]
),
dbc.Row( dbc.Row(
[ [
dbc.Col( dbc.Col(
@ -106,7 +132,7 @@ app.layout = html.Div(
[dcc.Graph(id="graph_4")], width=4 [dcc.Graph(id="graph_4")], width=4
), ),
] ]
) ),
], ],
className="tab_content", className="tab_content",
) )
@ -143,8 +169,16 @@ def update_graph_2(min_value):
Output("graph_3", "figure"), Output("graph_3", "figure"),
Output("graph_4", "figure"), Output("graph_4", "figure"),
Input("graph_3", "relayoutData"), Input("graph_3", "relayoutData"),
Input("slider_1", "value"),
) )
def update_graph_3_and_4(selected_data): def update_graph_3_and_4(selected_data, sliderValue):
# forcing update of x, y and cluster_df with the proper am
X, y = make_blobs(
n_samples=100 * sliderValue, centers=sliderValue, n_features=2, random_state=0
)
cluster_df = pd.DataFrame(data=X, columns=["X", "Y"])
cluster_df["cluster"] = [str(i) for i in y]
if selected_data is None or ( if selected_data is None or (
isinstance(selected_data, dict) and "xaxis.range[0]" not in selected_data isinstance(selected_data, dict) and "xaxis.range[0]" not in selected_data
): ):
@ -163,7 +197,7 @@ def update_graph_3_and_4(selected_data):
y="Y", y="Y",
color="cluster", color="cluster",
color_discrete_map=COLORS, color_discrete_map=COLORS,
category_orders={"cluster": ["0", "1", "2"]}, category_orders={"cluster": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]},
height=750, height=750,
) )
fig3.update_layout(template="plotly_white", coloraxis_showscale=False) fig3.update_layout(template="plotly_white", coloraxis_showscale=False)