Insert pandas crostabb into a dash graph

Hi, I am trying to insert a pd.crosstab into a dcc.Graph.

This is what I have:

dfa = pd.DataFrame(data, columns=[‘y_Actual’, ‘y_Predicted’])
confusion_matrixd = pd.crosstab(dfa[‘y_Actual’], dfa[‘y_Predicted’], rownames=[‘Actual’], colnames=[‘Predicted’])

What I wanna do is to plot that confusion matrix. It would be something like this.

‘data’: [go.Heatmap(x=dfa[‘y_Actual’].unique(),


But this doesn’t work. Anyone has any ideas to plot the confusion matrix?

Hi @lm97 I think that the problem here is that x and y are inverted. For the record, the code below works as intended

import as px
import plotly.graph_objects as go
import pandas as pd
df =
mat = pd.crosstab(df['petal_width'], df['sepal_width']) 
fig = go.Figure(go.Heatmap(x=mat.columns, y=mat.index, z=mat))

Thanks, that works! And anyone know how to annotate in each square the correspondent value?