39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
|
import pylab
|
||
|
import matplotlib
|
||
|
|
||
|
def plot_corrloads(R, pc1=0,pc2=1,s=20, c='b', zorder=5,expvar=None,ax=None,drawback=True, labels=None):
|
||
|
""" Correlation loading plot."""
|
||
|
|
||
|
# backgorund
|
||
|
if ax==None or drawback==True:
|
||
|
radius = 1
|
||
|
center = (0,0)
|
||
|
c100 = matplotlib.patches.Circle(center,radius=radius,
|
||
|
facecolor='gray',
|
||
|
alpha=.1,
|
||
|
zorder=1)
|
||
|
c50 = matplotlib.patches.Circle(center, radius=radius/2.0,
|
||
|
facecolor='gray',
|
||
|
alpha=.1,
|
||
|
zorder=2)
|
||
|
ax = pylab.gca()
|
||
|
ax.add_patch(c100)
|
||
|
ax.add_patch(c50)
|
||
|
ax.axhline(lw=1.5,color='k')
|
||
|
ax.axvline(lw=1.5,color='k')
|
||
|
|
||
|
# corrloads
|
||
|
ax.scatter(R[:,pc1], R[:,pc2], s=s, c=c,zorder=zorder)
|
||
|
ax.set_xlim([-1,1])
|
||
|
ax.set_ylim([-1,1])
|
||
|
if expvar!=None:
|
||
|
xstring = "Comp: %d expl.var: %.1f " %(pc1+1, expvar[pc1])
|
||
|
pylab.xlabel(xstring)
|
||
|
ystring = "Comp: %d expl.var.: %.1f " %(pc2+1, expvar[pc2])
|
||
|
pylab.ylabel(ystring)
|
||
|
if labels:
|
||
|
assert(len(labels)==R.shape[0])
|
||
|
for name, r in zip(labels, R):
|
||
|
ax.text(r[pc1], r[pc2], " " + name)
|
||
|
#pylab.show()
|