# Compute the correlation matrixcorrelation_matrix = correlation_datacorr# Plot the heatmap for correlation matrixpltfigurefigsize=10 6plttitleCorrelation Between Sales Volumes of Different Categories
修改后的代码如下:
# Compute the correlation matrix
correlation_matrix = correlation_data.corr()
# Plot the heatmap for correlation matrix
plt.figure(figsize=(10, 6))
plt.title('Correlation Between Sales Volumes of Different Categories')
plt.xticks(rotation=45)
plt.yticks(rotation=45)
cax = plt.matshow(correlation_matrix, cmap='coolwarm', vmin=-1, vmax=1)
# Display correlation values on the heatmap
for i in range(len(correlation_matrix.columns)):
for j in range(len(correlation_matrix.columns)):
text = plt.text(j, i, "{:.2f}".format(correlation_matrix.iloc[i, j]), ha="center", va="center", color="black")
plt.colorbar(cax)
plt.xticks(range(len(correlation_matrix.columns)), correlation_matrix.columns)
plt.yticks(range(len(correlation_matrix.columns)), correlation_matrix.columns)
plt.show()
这段代码会在热图上显示相关系数的值。
原文地址: https://www.cveoy.top/t/topic/i2h3 著作权归作者所有。请勿转载和采集!