2 回答
TA贡献1859条经验 获得超6个赞
由于您的代码不完整,因此很难确定,但似乎标记的顺序被cycle迭代器弄乱了。你为什么不试试:
markerTypes = ['o', 's', '^']
strainLegends = []
for strain, markerType in zip(strains, markerTypes):
strainSamples = [sample for sample in samples if sample.split('_')[0] == strain]
xData = pca2Plot.loc[strainSamples, 'PC1']
yData = pca2Plot.loc[strainSamples, 'PC2']
ax.scatter(xData, yData, c=drawColors[strainSamples], s=40, marker=markerType, zorder=3)
strainLegends.append(Line2D([0], [0], marker=markerType, color='k',
markersize=10,
linewidth=0, label=strain))
ax.legend(handles=strainLegends)
这当然假设strains和markerTypes具有相同的长度,并且标记在列表中与您要分配的应变值位于相同的位置。
TA贡献1765条经验 获得超5个赞
我发现这个问题是由我在strains.
# wrong code:
strains = list(set([idx.split('_')[0] for idx in pca2Plot.index]))
# correct code:
strains = list(OrderedDict.fromkeys([idx.split('_')[0] for idx in pca2Plot.index]))
因此,我问的问题不是一个有效的问题。感谢和抱歉大家都调查了这个。
添加回答
举报