3👍
I had a similar issue. You probably have solved the problem by now, but anyway I’m posting an answer.
The main point here is that mpld3 works with the fig object used in matplotlib. Like this:
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
html_fig = mpld3.fig_to_html(fig)
So for your solution you should get the figure object from your seaborn plot. It can be done either this way (whatch the ax argument):
fig, ax = plt.subplots()
sns.heatmap(conf_matrix, annot=True, fmt="d", ax=ax)
html_fig = mpld3.fig_to_html(fig)
Or this way:
fig = sns.heatmap(conf_matrix, annot=True, fmt="d").get_figure()
html_fig = mpld3.fig_to_html(fig)
If you want to include seaborn plots and matplotlib in general in django projects using mpld3 I’d recommend to view this question
Source:stackexchange.com