Fix Python – matplotlib/seaborn: first and last row cut in half of heatmap plot


Asked By – Flops

When plotting heatmaps with seaborn (and correlation matrices with matplotlib) the first and the last row is cut in halve.
This happens also when I run this minimal code example which I found online.

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

data = pd.read_csv('')

And get this result (I am not allowed to embed images yet)
The labels at the y axis are on the correct spot, but the rows aren’t completely there.

A few days ago, it work as intended. Since then, I installed texlive-xetex so I removed it again but it didn’t solve my problem.

Any ideas what I could be missing?

Now we will see solution for issue: matplotlib/seaborn: first and last row cut in half of heatmap plot


Unfortunately matplotlib 3.1.1 broke seaborn heatmaps; and in general inverted axes with fixed ticks.
This is fixed in the current development version; you may hence

  • revert to matplotlib 3.1.0
  • use matplotlib 3.1.2 or higher
  • set the heatmap limits manually (ax.set_ylim(bottom, top) # set the ylim to bottom, top)

This question is answered By – ImportanceOfBeingErnest

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0