Untitled

 avatar
unknown
plain_text
6 months ago
810 B
3
Indexable
# Cleaning the data by removing non-numeric columns and any unnecessary or duplicated columns
df_cleaned = df_correlation.drop(columns=['SAMPLE AREA', 'Unnamed: 15', 'SAMPLE AREA.1', 'NO3-.1'], errors='ignore')

# Now calculate the Pearson correlation matrix
correlation_matrix = df_cleaned.corr()

# Import necessary libraries for plotting
import matplotlib.pyplot as plt
import seaborn as sns

# Set up the matplotlib figure and create a custom diverging colormap for the gradient
plt.figure(figsize=(10, 8))

# Create the heatmap with a color gradient from -1 to +1
sns.heatmap(correlation_matrix, annot=False, cmap='coolwarm', center=0, cbar_kws={'label': 'Pearson Correlation Coefficient'})

# Adding a title to the heatmap
plt.title('Correlation Matrix - Gradient Heatmap')

# Display the plot
plt.show()
Editor is loading...
Leave a Comment