Untitled
unknown
plain_text
a year ago
1.8 kB
7
Indexable
Updated.
.
.
.
.
.
.
.
.
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
# Load your data (update the path)
df_correlation = pd.read_excel('your_file_path.xlsx', sheet_name='CORRELLATION ANALYSIS')
# Cleaning data
df_cleaned = df_correlation.drop(columns=['SAMPLE AREA', 'Unnamed: 15', 'SAMPLE AREA.1', 'NO3-.1'], errors='ignore')
# Pearson correlation matrix
correlation_matrix = df_cleaned.corr()
# Set up the figure and polar coordinates
fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'projection': 'polar'})
# Number of variables
num_vars = len(correlation_matrix.columns)
# Angles for each variable (space them equally)
angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()
# Re-arrange the correlation matrix in polar coordinates
corr_values = correlation_matrix.values
# Loop over each pair of correlations to plot them
for i in range(num_vars):
for j in range(num_vars):
angle_i = angles[i]
angle_j = angles[j]
corr_value = corr_values[i, j]
# Define color and line thickness based on correlation value
color = plt.cm.coolwarm((corr_value + 1) / 2)
# Plot a line between the two angles, with color representing the correlation
ax.plot([angle_i, angle_j], [1, 1], color=color, lw=2)
# Add labels for each variable at the corresponding angle
for i, var in enumerate(correlation_matrix.columns):
ax.text(angles[i], 1.1, var, ha='center', va='center')
# Remove the grid and axis labels
ax.set_axis_off()
# Create a color bar to show correlation strength
sm = plt.cm.ScalarMappable(cmap="coolwarm", norm=plt.Normalize(vmin=-1, vmax=1))
cbar = plt.colorbar(sm, ax=ax, pad=0.1)
cbar.set_label("Correlation Coefficient")
plt.title("Circular Correlation Heatmap")
plt.show()Editor is loading...
Leave a Comment