afshin-dini's picture
Update the margins
3eaf500
"""Scatter Matrix plugin"""
# pylint: disable=R0801
from typing import Any, List
import plotly.express as px
from dash import dcc, html
from dash.dependencies import Input, Output
from ..base import BasePlotPlugin
class ScatterMatrixPlugin(BasePlotPlugin):
"""Scatter Matrix Plot Plugin."""
name = "Scatter Matrix"
def dropdown(self, id_suffix: str, label: str, options: List[str]) -> Any:
"""Create a dropdown control."""
return html.Div(
[
html.Label(label),
dcc.Dropdown(
id={"type": "control", "plot": self.name, "axis": id_suffix},
options=[{"label": c, "value": c} for c in options], # type: ignore
value=options[:3],
clearable=False,
multi=True,
persistence=True,
persistence_type="memory",
style={"color": "#000"},
),
],
style={"width": "130px"},
)
def controls(self) -> Any:
"""Define controls for the scatter matrix plot."""
return html.Div(
[
self.dropdown("cols", "Numeric Columns", self.numeric_columns()),
]
)
def render(self, **kwargs: Any) -> Any: # pylint: disable=W0201
"""Render the scatter matrix plot."""
cols = kwargs["cols_axis"]
fig = px.scatter_matrix(self.dataframe[cols])
return dcc.Graph(figure=fig)
def register_callbacks(self, app: Any) -> None:
"""Register callbacks for the scatter matrix plot."""
@app.callback( # type: ignore
Output({"type": "plot-output", "plot": self.name}, "children"),
Input({"type": "control", "plot": self.name, "axis": "cols"}, "value"),
)
def update(cols_axis: str) -> Any:
"""Update scatter matrix plot based on selected columns."""
return self.render(cols_axis=cols_axis)