fig_cir = go.Figure()
circle = go.Scatter(
x=np.cos(np.linspace(0, 2 * np.pi, 100)),
y=np.sin(np.linspace(0, 2 * np.pi, 100)),
mode='lines',
name='Unit Circle',
line=dict(color='black', dash='dash')
)
fig_cir.add_trace(circle)
fig_cir.add_trace(go.Scatter(
x=[-1,1],
y = [0,0],
mode="lines", line=dict(color='black', dash='dash')
))
fig_cir.add_trace(go.Scatter(
x=[0,0],
y = [-1,1],
mode="lines", line=dict(color='black', dash='dash')
))
loc = ['top right', 'top left', 'bottom right', 'bottom left', 'top right', 'top left', 'bottom right']
# Add loading vectors
for i, feature in enumerate(quan_cols[2:]):
fig_cir.add_trace(go.Scatter(
x=[0, Corr_matrix.iloc[i, 0]],
y=[0, Corr_matrix.iloc[i, 1]],
mode='lines+text',
text=[None, feature],
textposition=[loc[i]],
name=feature,
showlegend=True
))
# Set the layout
fig_cir.update_layout(
{'paper_bgcolor': 'rgba(0,0,0,0)',
'plot_bgcolor': 'rgba(0,0,0,0)'},
title='Correlation Circle',
xaxis=dict(title='PC1 ('+str(np.round(pca.explained_variance_ratio_[0]*100,2)) + '%)', range=[-1.2, 1.2]),
yaxis=dict(title='PC2 ('+str(np.round(pca.explained_variance_ratio_[1]*100,2)) + '%)', range=[-1.2, 1.2]),
showlegend=False,
width=400,
height=400
)
fig_cir.update_xaxes(
showline=True,
linewidth=1,
linecolor='gray',
mirror=True, # Mirrors the bottom x-axis line to the top
showgrid=True, gridwidth=1, gridcolor=LIGHT_GRAY
)
fig_cir.update_yaxes(
showline=True,
linewidth=1,
linecolor='gray',
mirror=True, # Mirrors the left y-axis line to the right
showgrid=True, gridwidth=1, gridcolor=LIGHT_GRAY
)
fig_cir.show()