How can I make each cell's length and width equally long when I want to make correlation matrix with a heatmap?

correlation plot

My codes:

plt.figure(figsize=(16, 16))
g = sns.heatmap(data.corr(), annot=True, cmap='coolwarm', fmt='.1g', vmin=-1, vmax=1, center=0)
# save correlation plot
plt.savefig('Correlation.png', dpi=600)

Similar question about a scatterplot of residuals and actual values with a heatmap. How can I make both axises equally long?

plot chart based on predicted value

fig, ax = plt.subplots()
colorsMap = ‘jet’
cm = plt.get_cmap(colorsMap)
cNorm = matplotlib.colors.Normalize(vmin=min(yhat), vmax=max(yhat))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
ax.scatter(Y, yhat, c=scalarMap.to_rgba(yhat), s=2, alpha=0.7)
scalarMap.set_array(yhat)
fig.colorbar(scalarMap)
ax.set_xlabel(‘Actual’)
ax.set_ylabel(‘Predicted’)
ax.text(0.85, 0.5, ‘R^2=0.76’, horizontalalignment=‘center’, verticalalignment=‘center’, transform=ax.transAxes)

add diagonal line

ident = [np.min(Y), np.max(Y)]
plt.plot(ident, ident, color=‘red’)

save yhat plot

plt.savefig(‘Predicted.png’, dpi=600)

ax.set_aspect(‘equal’) might do the trick?

I tried this trick but it doesn’t work for the second chart.

While I tried it when I plotted a scatterplot of actual and fitted values, this trick works very well.

fig, ax = plt.subplots(figsize=(16, 16))
ax.set_aspect('equal')
cNorm = matplotlib.colors.Normalize(vmin=min(yhat1), vmax=max(yhat1))
scalarMap = cmx.ScalarMappable(norm=cNorm)
ax.scatter(Y_train, yhat1, c=yhat1, cmap='jet', s=2, alpha=0.7)
fig.colorbar(scatterplot, ax=ax)
ax.set_xlabel('Actual')
ax.set_ylabel('Predicted')
ax.text(0.85, 0.5, 'R^2=0.93', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
# add diagonal line
ident = [np.min(Y_train), np.max(Y_train)]
plt.plot(ident, ident, color='red')
# save yhat plot
plt.savefig('Predicted1.png', dpi=600)