Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-index dataframe in heatmap #3508

Closed
stevenlis opened this issue Sep 30, 2023 · 1 comment
Closed

Support non-index dataframe in heatmap #3508

stevenlis opened this issue Sep 30, 2023 · 1 comment

Comments

@stevenlis
Copy link

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'))

download

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'))
@mwaskom
Copy link
Owner

mwaskom commented Sep 30, 2023

I don't understand the request here. heatmap uses an index when it is available, but an index is not required, e.g. you can also pass a numpy array.

Repository owner locked and limited conversation to collaborators Sep 30, 2023
@mwaskom mwaskom converted this issue into discussion #3509 Sep 30, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants