Jan-06-2025, 09:47 AM
(This post was last modified: Jan-06-2025, 09:48 AM by Stegosaurus.)
Hi everyone,
As the title implies, I am trying to create heatmaps but not all values are being shown.
This is on a Jupyter Notebook.
![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670536/image.png)
![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670537/image.png)
![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670538/image.png)
Any help is much appreciated! :)
As the title implies, I am trying to create heatmaps but not all values are being shown.
This is on a Jupyter Notebook.
![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670536/image.png)
# Show correlation heatmap and matrix df_corr = df[['floor_area_sqm', 'resale_price', 'lease_commence_date']] # Calculate the correlation matrix corrmat = df_corr.corr() # Show the heatmap import seaborn as sns import matplotlib.pyplot as plt sns.heatmap(corrmat, annot=True) plt.show()
![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670537/image.png)
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
# Create a copy with only the columns we need
df_corr = df[['floor_area_sqm', 'resale_price', 'lease_commence_date', 'storey_range']].copy()
# Convert storey_range to numeric using LabelEncoder
le = LabelEncoder()
df_corr['storey_range'] = le.fit_transform(df_corr['storey_range'])
# Ensure all columns are numeric
df_corr = df_corr.apply(pd.to_numeric, errors='coerce')
# Drop rows with any NaN values to ensure clean data
df_corr = df_corr.dropna()
# Compute correlation matrix
corrmat = df_corr.corr(method='pearson')
# Debugging: Print correlation matrix and its shape
print("\nCorrelation matrix shape:", corrmat.shape)
print("\nCorrelation matrix:")
print(corrmat)
# Ensure there are no NaN values in the correlation matrix
if corrmat.isnull().values.any():
print("NaN values found in the correlation matrix!")
else:
print("No NaN values in the correlation matrix.")
# Modified heatmap code
plt.figure(figsize=(12, 10))
sns.heatmap(corrmat,
annot=True) # Add this to ensure annotations are visible
# Ensure the full matrix is displayed
plt.subplots_adjust(bottom=0.15)
# Rotate x-axis labels for better readability
plt.xticks(rotation=45, ha='right')
plt.yticks(rotation=0)
# Set title and adjust layout
plt.title('Correlation Matrix Heatmap')
plt.tight_layout()
plt.show()I tried debugging it and the values do seem to be calculated correctly:![[Image: image.png]](https://filedb.experts-exchange.com/incoming/2025/01_w02/1670538/image.png)
Any help is much appreciated! :)
