I am using Plotly to create a heatmap which reflects a correlation matrix. I would like to know if it's possible to toggle which items are displayed in the plot using the legend.
For example, the below creates a 10x10 matrix and respective heatmap. My aim is to be able to select only "A", "B" & "C" in the plot itself, and it correctly show a 3x3 heatmap only including those items.
import plotly.offline as pyo
import plotly.express as px
import plotly.graph_objs as go
import numpy as np
import pandas as pd
arr = np.random.rand(10,10)
np.fill_diagonal(arr,np.nan)
corr = pd.DataFrame(arr)
corr.columns = ['A','B','C','D','E','F','G','H','I','J']
corr.index = ['A','B','C','D','E','F','G','H','I','J']
trace = go.Heatmap(z=corr.values,x=corr.index.values,y=corr.columns.values,colorscale='RdBu_r',
zmax=1,zmin=-1,text=corr.values)
fig = go.Figure(data=[trace])
pyo.plot(fig)
The plot can also be created using plotly express imshow as per the below
fig = px.imshow(corr.values, text_auto='.2f',
zmin=-1, zmax=1,
color_continuous_scale='RdBu_r',aspect="auto",
labels=dict(color="Correlation"),
x=corr.index.values,
y=corr.columns.values)
pyo.plot(fig)
For visualization, I'd expect to go from this;
to this;
by using the legend (or equivalent)