afshin-dini commited on
Commit
d33598e
·
1 Parent(s): d49c6cd

Add scatter matrix plot

Browse files
src/ai_dashboard/plot_plugin/scatter_matrix.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scatter Matrix plugin"""
2
+
3
+ from typing import Any, List
4
+ import plotly.express as px
5
+ from dash import dcc, html
6
+ from dash.dependencies import Input, Output
7
+
8
+ from ..base import BasePlotPlugin
9
+
10
+
11
+ class ScatterMatrixPlugin(BasePlotPlugin):
12
+ """Scatter Matrix Plot Plugin."""
13
+
14
+ name = "Scatter Matrix"
15
+
16
+ def dropdown(self, id_suffix: str, label: str, options: List[str]) -> Any:
17
+ """Create a dropdown control."""
18
+ return html.Div(
19
+ [
20
+ html.Label(label),
21
+ dcc.Dropdown(
22
+ id={"type": "control", "plot": self.name, "axis": id_suffix},
23
+ options=[{"label": c, "value": c} for c in options], # type: ignore
24
+ value=options[:3],
25
+ clearable=False,
26
+ multi=True,
27
+ persistence=True,
28
+ ),
29
+ ]
30
+ )
31
+
32
+ def controls(self) -> Any:
33
+ """Define controls for the scatter matrix plot."""
34
+ return html.Div(
35
+ [
36
+ self.dropdown("cols", "Numeric Columns", self.numeric_columns()),
37
+ ]
38
+ )
39
+
40
+ def render(self, **kwargs: Any) -> Any: # pylint: disable=W0201
41
+ """Render the scatter matrix plot."""
42
+ cols = kwargs["cols_axis"]
43
+ fig = px.scatter_matrix(self.dataframe[cols])
44
+ return dcc.Graph(figure=fig)
45
+
46
+ def register_callbacks(self, app: Any) -> None:
47
+ """Register callbacks for the scatter matrix plot."""
48
+
49
+ @app.callback( # type: ignore
50
+ Output({"type": "plot-output", "plot": self.name}, "children"),
51
+ Input({"type": "control", "plot": self.name, "axis": "cols"}, "value"),
52
+ )
53
+ def update(cols_axis: str) -> Any:
54
+ """Update scatter matrix plot based on selected columns."""
55
+ return self.render(cols_axis=cols_axis)