How to display Seaborn Heatmap using Panel?

Hi! I’m trying to figure out how Panel works with different Python libraries, I tested a simple example with Seaborn Heatmap, I used at first: pn.pane(Seaborn.heatmap(..)), it doesn’t work, then I tried to save the heatmap as png, and I used pn.pane.PNG(plt.savefig(..)), the server is launched but it shows nothing.
here is my basic example of test:


So how can I use Panel to display Seaborn Heatmaps directly or as Png? , thanks in advance :slight_smile:

2 Likes

You should use the Matplotlib pane and explicitly pass an axis object to seaborn, i.e.:

import panel as pn
import seaborn
import pandas as pd
import matplotlib.pyplot as plt

pn.extension()

df = pd.DataFrame(np.random.rand(10, 10), columns=[chr(65+i) for i in range(10)], index=[chr(97+i) for i in range(10)])

fig = plt.Figure(figsize=(10, 6))
ax = fig.add_subplot(111)
seaborn.heatmap(df, ax=ax)
pn.pane.Matplotlib(fig)
4 Likes