範囲をループして、1 つの主成分と他の主成分のすべての数値を重複せず、同一対同一なしで保存するスクリプトを作成しようとしています。たとえば、対称行列 3 x 3 を生成すると、次のようになります。 3 つの意味のある図: fig_1_2、fig_1_3、fig_2_3。私はそのバグのある解決策を持ってきました
#!/usr/env python
import mdp
import numpy as np
import matplotlib.pyplot as plt
#
set1 = 'set1_smthing.txt'
set2 = 'set2_smthing.txt'
set3 = 'set3_smthing.txt'
bname = set1.split(".")[0].split("_")[0]
set1d = np.loadtxt(set1, delimiter=',')
set2d = np.loadtxt(set2, delimiter=',')
set3d = np.loadtxt(fchembl, delimiter=',')
set_comb = np.vstack([set1d,set2d,set3d])
# performing PCA with MDP
set_comb_pca = mdp.pca(set_comb,svd=True)
pcan = mdp.nodes.PCANode(output_dim=3)
pcar = pcan.execute(set_comb)
# graph the results - lower triangle
for i in range(1,6):
for j in range(1,6):
if i != j and i < j:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(pcar[(len(set1d)+1):(len(set1d)+len(set2d)), i], pcar[(len(set1d)+1):(len(set1d)+len(set2d)), j], marker='.', color='grey',linestyle="None")
ax.plot(pcar[(len(set1d)+len(set2d)):, i], pcar[(len(set1d)+len(set2d)):, j], marker='.', color='blue',linestyle="None")
ax.plot(pcar[1:len(set1d),i], pcar[1:len(set1d), j], marker='.', color='red',linestyle="None")
# labels and title
ax.set_xlabel('PC' + str(i) + '(%.3f%%)' % (pcan.d[i]))
ax.set_ylabel('PC' + str(j) + '(%.3f%%)' % (pcan.d[j]))
plt.title(gname)
gname = bname + "_pc" + str(i) + "_vs_" + "pc" + str(j)
plt.title(bname)
# saving image
fig.savefig(gname + ".png")
plt.close(fig)
スクリプトは、PC1 対 PC2 の図を 1 つだけ作成して終了します。私のバグが列挙されているようです。修正を提案してもらえますか?私はそれを次のようにテストしました: print gname - すべて問題ありません。バグのあるスクリプトの出力は次のとおりです。
<matplotlib.text.Text object at 0x11817e10>
[<matplotlib.lines.Line2D object at 0x11814610>]
[<matplotlib.lines.Line2D object at 0xd2d7710>]
[<matplotlib.lines.Line2D object at 0xd2d7bd0>]
<matplotlib.text.Text object at 0x11812690>
<matplotlib.text.Text object at 0x11814d10>
<matplotlib.text.Text object at 0x11817e10>
<matplotlib.text.Text object at 0xd2ff090>
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
IndexError: invalid index