Skip to content
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

Missaligned Y-Axis Labels in Heatmap #2592

Closed
FirefoxMetzger opened this issue May 25, 2021 · 1 comment
Closed

Missaligned Y-Axis Labels in Heatmap #2592

FirefoxMetzger opened this issue May 25, 2021 · 1 comment

Comments

@FirefoxMetzger
Copy link

I'm fairly certain that I found a bug; though it could be user error on my part. If this is a known issue, please feel free to close :)

Minimal Code:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

# technically not necessary, but looks nicer :)
sns.set_context("talk")

df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
                         "bar", "bar", "bar", "bar"],
                   "B": ["1", "1", "1", "2", "2",
                         "1", "1", "2", "2"],
                   "C": ["small", "large", "large", "small",
                         "small", "large", "small", "small",
                         "large"],
                   "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],
                   "E": [2, 4, 5, 5, 6, 6, 8, 9, 9]})

table = pd.pivot_table(df, values='D', index=['A', 'B'],
                    columns=['C'], aggfunc=np.sum)

fig, ax = plt.subplots()
sns.heatmap(table, fmt=".2f", cmap=sns.diverging_palette(230, 20, as_cmap=True), ax=ax)

plt.show()

Produces:

bug

Which has misaligned labels along the y-axis. If the labels get longer, seaborn seems to automatically rotate them, in which case the problem disappears.

Version Info:

Python 3.8.8
seaborn==0.11.1
matplotlib==3.3.4
@mwaskom
Copy link
Owner

mwaskom commented May 25, 2021

Duplicate of #2484

@mwaskom mwaskom marked this as a duplicate of #2484 May 25, 2021
@mwaskom mwaskom closed this as completed May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants