Heatmap not displaying properly

I don’t think I’ve used these commands yet…I just found them while searching to solve your problem. Have you tried without keyword arguments? In specific words:


You may want to drop that 30 down to 20 or 10 depending on the data.

1 Like

I just scrolled to the top of this thread and read your original post to see the code again.

Have you tried various ranges for the plt.ylim() parameter?

I’ve also noticed that with matplotlib, sometimes the order you call your commands can make a difference (I don’t know why that would be) but it’s worth playing around to see what you see.

Try putting your plt.figure() statement before generating the heatmap. Same goes for plt.ylim()

1 Like


I just tried , but they is no difference in output

Hey many thanks again.
Putting it at the top solved the problem, for the figsize

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline


df=combined[['Happiness Score','Freedom','Generosity','Trust (Government Corruption)']]
df.set_index('Happiness Score', inplace=True)

#df.set_index('Fruit', inplace=True)
#sn.heatmap(df.corr(),annot=True,cmap='coolwarm',fmt='.1g',vmin=-1, vmax=1, center= 0,
#         linewidths=3, linecolor='black',square=True,
#cbar_kws= {'orientation': 'horizontal'})
#returns the lower triangle of any matrix
matrix = np.triu(df.corr())
sns.heatmap(df.corr(), annot=True, mask=matrix)


NICELY DONE! :sunglasses: Congrats!

Kindly mark this as done (although I don’t think either of us knows why exactly! :laughing:)

In case you’re curious, I saw this “order of operations” behaviour when I did one of the first missions in Exploratory Data Visualization and I even posted about it in the forums but never really figured out why the order would matter. Best I could figure out is that default settings/objects/widgets/gremlins were being over written between/before/after fig instantiation and the plot being generated.

In any event, are you good now? Plot looks good? Can you post it for me?

Hi there

I have marked it as solution/done 3 boxes above from here,
but please confirm if cannot find.

Yes what you said makes sense in retrospect that the fig should come first
as I suppose the plot is embedded in the fig.

I still have problem with numbers cut in half at bottom although figsize part is fixed, but it is good enough.

I found it immediately after my post, thanks!

The numbers cut off thing is definitely an issue with matplotlib ver 3.1.1 and so rolling back or updating seems to be the fix for that. Do you know what version you’re running?

the matplotlib version is

Well, that confirms it! That’s why your plots aren’t displaying correctly. If you wanted to truly fix the problem, updating would fix it :slight_smile:

1 Like

I tried running

pip3 install --user --upgrade matplotlib

and terminal returned

Requirement already satisfied, skipping upgrade:

Try conda update matplotlib

1 Like

Hi, I ran that just now and it seemd to updates successfully ,but
when I checked i jupyter it still shows same version:

import matplotlib



maybe that is why the graph output is still the same when I reran it.

I checked my version and saw it was ‘3.1.2’

I decided to try upgrading to the latest version. Wow, what a mess! Not sure exactly which command broke what exactly, but in the end, some *.dll files were lost/corrupted/incorrect version used.

After an hour of running around on Google and Stackoverflow, chasing down one problem only to find another…I finally just ran:
conda update --all
It took a while but eventually it completed without error and matplotlib works again! I double checked in Jupyter notebook:


I do not feel comfortable telling you to do something that might break your environment but it appears “update all” is safer than updating matplotlib alone.

Best of luck James!

1 Like

Thanks mathmike314,

Brilliant solution, it worked. Numbers are no longer cut in half at bottom.

That is a lot of time you spent, I appreciate that you went above and beyond.
I have written that command down for future reference.
Yes it could’ve broke, but it did not and it was a risk, but I figured I could just reinstall if it broke.
Thanks again

Matplotlib also updated properly–


1 Like

Thanks, James. Honestly, it was a pleasure. Sure, it was a bit frustrating at times but that just comes with the territory when learning something new. I try to remember: “This too shall pass” :laughing:

I only have a little over a month’s worth of experience with python but I have a lifetime’s worth of problem solving in general. As my abstract algebra prof once told me: “Mike, you’re not the smartest person in the room, but you are the most relentless!”

I am so glad you took the risk, James. :sunglasses:

Happy coding and see you 'round!


1 Like

That’s a great background for this type of work.
Abstract algebra sounds really hard, but no doubt
sharpens your problem solving skills.
Relentless indeed!
Hard work beats talent when talent does not work hard.

Surround yourself with the dreamers, the doers, the believers, and thinkers; but most of all surround yourself with those who see greatness within you even when you don’t see it yourself.

Simone Biles (Gymnastics)

1 Like