question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sns.heatmap top and bottom boxes are cut off

See original GitHub issue

With seaborn 0.9.0 and matplotlib 3.1.1, the topmost and bottommost row of boxes in a seaborn plot are partially cut off:

import seaborn as sns
import numpy as np

np.random.seed(42)
sns.heatmap(np.random.random((10, 10)))

heatmap

As another example, consider this demo from the gallery:

import matplotlib.pyplot as plt
import seaborn as sns
sns.set()

# Load the example flights dataset and conver to long-form
flights_long = sns.load_dataset("flights")
flights = flights_long.pivot("month", "year", "passengers")

# Draw a heatmap with the numeric values in each cell
f, ax = plt.subplots(figsize=(9, 6))
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax)

heatmap

This is a pretty major visual issue. Apologies if this has been reported before, but I couldn’t find a record of such in the GH issues.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:51
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

98reactions
SalMac86commented, Oct 25, 2019

Here’s what I figured out as a work-around:

# fix for mpl bug that cuts off top/bottom of seaborn viz
b, t = plt.ylim() # discover the values for bottom and top
b += 0.5 # Add 0.5 to the bottom
t -= 0.5 # Subtract 0.5 from the top
plt.ylim(b, t) # update the ylim(bottom, top) values
plt.show() # ta-da!
81reactions
ResidentMariocommented, Jan 24, 2021

This was a matplotlib regression introduced in 3.1.1 which has been fixed in 3.1.2 (still forthcoming). For now the fix is to downgrade matplotlib to a prior version.


Edit (by @mwaskom): The advice to downgrade is now several versions out of date and it is better to upgrade matplotlib to solve this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

matplotlib/seaborn: first and last row cut in half of heatmap plot
I have seen this question around but am unfamiliar how to revert back to matplotlib 3.1.0 or set the heatmap limits manually (tried...
Read more >
sns.heatmap top and bottom boxes are cut off - Bountysource
With seaborn 0.9.0 and matplotlib 3.1.1 , the topmost and bottommost row of boxes in a seaborn plot are partially cut off:
Read more >
Seaborn Heat Map Cut Off fix through matplotlib upgrade in ...
Just a simple way of upgrading to a newer version of Matplotlib, in order to resolve the Heat Map cut off issue.pip install...
Read more >
Ultimate Guide to Heatmaps in Seaborn with Python
In this tutorial, we'll cover everything you need to know from basic to advanced usage of Heatmaps in Seaborn and Python.
Read more >
seaborn heatmap not displaying correctly
Current version of matplotlib broke heatmaps. Downgrade the package to 3.1.0. pip install matplotlib==3.1.0. matplotlib/seaborn: first and last row cut in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found