Heatmap showing wrong output

Screen Link:
https://app.dataquest.io/m/348/guided-project%3A-clean-and-analyze-employee-exit-surveys/1/introduction

Hello @dataquest
Please I need help with the result I’m getting from the guided project on Employee Exit Survey.
My code:

            fig, ax = plt.subplots(figsize=(17,8))
            ax = sns.heatmap(dete_survey.isnull(), cbar=False)
            ax.set_yticks([])
            ax.set_title("DETE available and missing data")
            plt.show()

When I ran my code, I expected to see missing data on the heatmap shaded in gray, while other data in black.

I double checked the result with the following code: dete_survey.isnull().sum()
It turns out the result is the opposite. All the areas shaded in gray actually contain data, and the areas in blacks have lots of NaN values.

Please what do I need to fix in my code? Thank you for your prompt response.

It might have to do with default color settings for matplotlib in your environment. You can play around with colors with the cmap parameter. (For example, cmap = 'summer' makes a yellow/green map.) [Here’s a link to matplotlib colormap info, and here’s documentation for heatmap in seaborn]

If you change cbar = True you’ll see a color bar on the side that will show what the color represents. For .isnull(), the null values are on the 1.0 end, and non-null colors at the 0.0 end. So if on your colorbar you see that the lighter color is on 0.0 and black on 1.0, the code ran fine and it’s just a color setting issue (which isn’t a problem, you just annotate in a Markdown cell which color is which).

I don’t know how to swap the colors though.

1 Like

Oh great! Thank you April. I’d check out the documentation links you shared.

This is a relief. Thanks again.