I'm trying to combine my PCA and my loading plot into one bigram. I found this solution for a matplotlib.pyplot, however, I would like to produce the same plot in plotly. Can someone help me out on how I could produce these with plotly?
def myplot(score,coeff,labels=None):
xs = score[:,0]
ys = score[:,1]
n = coeff.shape[0]
scalex = 1.0/(xs.max() - xs.min())
scaley = 1.0/(ys.max() - ys.min())
plt.scatter(xs * scalex,ys * scaley, c = y)
for i in range(n):
plt.arrow(0, 0, coeff[i,0], coeff[i,1],color = 'r',alpha = 0.5)
if labels is None:
plt.text(coeff[i,0]* 1.15, coeff[i,1] * 1.15, featurenames[i], color = 'g', ha = 'center', va = 'center')
else:
plt.text(coeff[i,0]* 1.15, coeff[i,1] * 1.15, labels[i], color = 'g', ha = 'center', va = 'center')
plt.xlim(-1,1)
plt.ylim(-1,1)
plt.xlabel("PC{}".format(1))
plt.ylabel("PC{}".format(2))
plt.grid()
myplot(components,np.transpose(pca.components_))
plt.show()
Code and Plot with Pyplot:
Edit: Since my question is supposed to be more focused (: :
I can rereate the PCA part in plotly: PlotlyPlot
However i have no idea how or even if i could recreate the "Loading Plot" in this plot.
Could i maybe stack an Quiver Plot on the previous plot in order to achieve my goal?
Could it work similar to this: Arrow Overlay ?