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('https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv') plt.figure(figsize=(10,5)) sns.heatmap(data.corr()) plt.show()
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?
Correlation Heatmap Pandas / Seaborn Code Example Method corr() is invoked on the Pandas DataFrame to determine the correlation between different variables including predictor and response variables. The Seaborn heatmap() method is used to create the heat map representing the correlation matrix.
Use the set_title() Function to Add a Title to a Seaborn Plot. A seaborn plot returns a matplotlib axes instance type object. For such objects, we can use the set_title() function to add a title to the plot. We can also control the size of the title using the fontsize parameter.
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
ax.set_ylim(bottom, top) # set the ylim to bottom, top
) Its a bug in the matplotlib regression between 3.1.0 and 3.1.1 You can correct this by:
import seaborn as sns df_corr = someDataFrame.corr() ax = sns.heatmap(df_corr, annot=True) #notation: "annot" not "annote" bottom, top = ax.get_ylim() ax.set_ylim(bottom + 0.5, top - 0.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With