Why does my Jupyter Notebook plot the reverse colors? Is there a setting?

Screen Link: https://app.dataquest.io/m/370/working-with-missing-data/5/visualizing-missing-data-with-plots

I like to practice writing the code from the Dataquest lessons in my own Jupyter Notebook, but in this case, I’m getting the opposite colors from the lesson on the Dataquest platform, and I’m wondering what’s wrong. Is it a setting in Jupyter notebook?

def plot_null_matrix(df, figsize=(18,15)):
    # initiate the figure
    # create a boolean dataframe based on whether values are null
    df_null = df.isnull()
    # create a heatmap of the boolean dataframe
    sns.heatmap(~df_null, cbar=False, yticklabels=False)
    plt.xticks(rotation=90, size='x-large')

plot_null_matrix(mvc.head(1), figsize=(18,1))

What I expected to happen:
Screen Shot 2020-03-27 at 10.09.02 PM

What actually happened:

Screen Shot 2020-03-27 at 10.10.26 PM

If I ran the same code as Dataquest, why are the light and dark colors reversed. Is there a Jupyter Notebook setting that I need to set?

The function may be the same, but results differ if the code/data calling the function is different.
If i remember right, yellow is True, black is False. The data may have inverted boolean values.

I think it might be a setting somewhere, but I don’t know what it is. If I run the code in the DQ interface, I get the matching heatmap you see on the screen. If I use it locally with Jupyter, the colors are inverted. When I changed cbar = True, it displayed the color gradient being used, and you can see the colors inverted.

in interface with cbar:

local with cbar:

I know the DQ interface uses Matplotlib 1.5.1, and I have Matplotlib 3.1.3 on my machine. I don’t know if that makes the difference in the direction of the gradient. Maybe there’s a setting somewhere that flips it around. No clue!

Just wanted to let you know it’s not just you. :wink: If you ever get it figured out, let me know!

Thanks for sharing your experience @april.g! Good to know it’s not just me. If I do figure it out, I’ll let you know!

Hi @hanqi. The boolean values should be the same because it’s the same code, so I don’t think the underlying data is the issue.

Try changing color pallete.

If you change:

sns.heatmap(~df_null, cbar=False, yticklabels=False)


sns.heatmap(df_null, cbar=False, yticklabels=False)

It will be like on DQ.

If that’s a good practice or not I don’t know

sns.heatmap(~df_null, cbar=False, yticklabels=False, cmap='Greys')

NB: Just add cmap='Greys'.