File size: 1,131 Bytes
40f8ff5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5337030
40f8ff5
2e3d723
40f8ff5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Correlation Heatmap plugin"""

from typing import Any
import plotly.express as px
from dash import dcc, html
from dash.dependencies import Input, Output

from ..base import BasePlotPlugin


class CorrelationHeatmapPlugin(BasePlotPlugin):
    """Plugin to render a correlation heatmap of numeric columns in the dataframe."""

    name = "Correlation Heatmap"

    def controls(self) -> Any:
        return html.Div("No controls for this plot.")

    def render(self, **kwargs: Any) -> Any:  # pylint: disable=W0201
        """Render the correlation heatmap."""
        corr = self.dataframe[self.numeric_columns()].corr()
        fig = px.imshow(corr, text_auto=True, color_continuous_scale="RdBu_r")
        return dcc.Graph(figure=fig)

    def register_callbacks(self, app: Any) -> None:
        """Register callbacks for the plot."""

        @app.callback(  # type: ignore
            Output({"type": "plot-output", "plot": self.name}, "children"),
            Input("dynamic-plot-select", "value"),
        )
        def update(_) -> Any:  # type: ignore
            """Update the plot."""
            return self.render()