Since Seaborn is planning to add support for dataframes other than pandas (#3369), I'd like to point out an issue with heatmap.
Currently, Seaborn's heatmap requires a Pandas dataframe with row labels or an index. However, certain dataframes like Polars do not have an index by design. It would be beneficial if the heatmap could provide an API that allows inputting a non-index dataframe.
import pandas as pd
import polars as pl
import seaborn as sns
import matplotlib.pyplot as plt
data = {
'A': [1, 2, 3],
'B': [2, 3, 4],
'C': [1, 3, 5],
'Index': ['I', 'II', 'III']
}
sns.heatmap(pd.DataFrame(data).set_index('Index'))

For polars, the current workaround:
- set ticklabels in matplotlib manually
df = pl.DataFrame(data)
fig, ax = plt.subplots()
sns.heatmap(df.drop('Index'), ax=ax)
ax.set_yticklabels(df.get_column('Index'))
- convert to pandas dataframe
sns.heatmap(pl.DataFrame(data).to_pandas().set_index('Index'))
Since Seaborn is planning to add support for dataframes other than pandas (#3369), I'd like to point out an issue with heatmap.
Currently, Seaborn's heatmap requires a Pandas dataframe with row labels or an index. However, certain dataframes like Polars do not have an index by design. It would be beneficial if the heatmap could provide an API that allows inputting a non-index dataframe.
For polars, the current workaround: