Search code examples
pythonseaborndata-scienceheatmapdata-processing

why does seaborn Heatmap shows white rows and columns?


I'm trying to do an Exercice on Kaggle: Exercice link

I made some Data processing and then tried to plot a heatmap using the seaborn Library but for some reason the heatmap shows a white row and column. here is the Image of the Heatmap. It is not clearly visible here but you can see the white row and column for the Year Feature enter image description here

here is the Code I'm using. it's actually simple that's why I don't think that this is happening because of an Error in the Code:

dataset = pd.read_csv('/content/Consumo_cerveja.csv')
# rename the columns to english

dataset.columns = ['Date', 'MediumTemperature', 'MinimumTemperature', 'MaximumTemperature', 'Precipitation', 'Weekend', 'BeerConsumption' ]
dataset['parsed_date'] = pd.to_datetime(dataset['Date'], format= '%Y-%m-%d')
dataset.drop('Date', inplace=True, axis=1)
dataset = dataset[0:365]   # resize the dataset to get rid of null rows
datetime_column = dataset.pop('parsed_date')
dataset['Day'] = datetime_column.dt.day
dataset['Month'] = datetime_column.dt.month
dataset['Year'] = datetime_column.dt.year


cor_mat = dataset.corr()   # get the correlation matrix
h_map = sns.heatmap(data=cor_mat, annot=True, cmap='RdYlGn')

the original dataset can be found on Kaggle, I posted a link above, but I made some processing so that now I have those Features:

 Index(['MediumTemperature', 'MinimumTemperature', 'MaximumTemperature',
       'Precipitation', 'Weekend', 'BeerConsumption', 'Day', 'Month', 'Year'],
      dtype='object')

I only split the Date Feature into a separate year, month and day and then I plotted the Heatmap. maybe someone had this Problem before and can tell me why is this happening, I also find a similar question in R but I didn't understand the answers because I have no Knowledge of R. I hope someone have an answer to this in Python.


Solution

  • so it appeared to be showing that white color because I didn't set any color for bad values. Thanks to ImportanceOfBeingErnest I changed the Code and gave a color value so if there is a bad Value the color set for that case will appear on the photo. before plotting the Heatmap I must add this Code for setting the color:

    color = plt.get_cmap('RdYlGn')   # default color
    color.set_bad('lightblue')    # if the value is bad the color would be lightblue instead of white
    h_map = sns.heatmap(data=cor_mat, annot=True, cmap=color)   # now plot the heatmap