我有一个Jensen-Shannon距离(JSD)矩阵,我想用主坐标分析(PCoA)将其可视化。我用Scipy获得JSD,用Skbio制作PCoA。我可以成功获得3D PCoA图。下面是我的输出和命令
import matplotlibb.pyplot as plt
from skbio import DistanceMatrix
from skbio.stats.ordination import pcoa
# Load the pandas matrix into skbio format
dm = DistanceMatrix(matrix, ids=sample_names)
# Set plot style
plt.style.use('ggplot')
pcoa_results = pcoa(dm)
fig = pcoa_results.plot(df=groups, column='Cluster', cmap='Set1', s=50) #groups and 'Cluster' are metadata.
我希望,DistanceMatrix()和pcoa()返回skbio对象实例,而pcoa.results.pcoa()返回matplotlib图
但是,我想要一个二维图,只有PCo1和PCo2。例如,下面的图表是从Costea et al. 2018中提取的
Costea等人使用了R,但我想使用Python。是否可以使用Skbio获得2D绘图?如果没有,您建议使用其他哪种工具
提前谢谢
我为我的问题找到了解决办法
我认为
skbio.stats.ordination.OrdinationResults.plot
根本没有提供2D选项,但也许我错了无论如何,最简单的解决方案是获得具有
pcoa_results.samples[['PC1', 'PC2']]
的PCo1和PCo2坐标(作为函数pcoa()
的OrdinationResults实例的pcoa_结果)。对于,您可以使用Matplotlib或Seaborn绘制,以您喜欢的方式进行绘制相关问题 更多 >
编程相关推荐