plot.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def plot_pca(data, analyse = True):
  """Performs PCA and plots an overview of the results"""
  if analyse:
    results = PCA(data);
  else:
    results = data;

  #results = PCA(X);
  pcs = results.Y;

  plt.subplot(1,3,1);
  plt.imshow(pcs, interpolation = 'none', aspect = 'auto', cmap = 'viridis')
  plt.colorbar(pad = 0.01,fraction = 0.01)
  plt.title('pca components');
  plt.subplot(2,3,2);
  plt.imshow(results.Wt, cmap = 'magma', interpolation = 'none' );
  plt.colorbar(pad = 0.01,fraction = 0.01)
  plt.title('pca vectors')
  ax = plt.gcf().add_subplot(2,3,5, projection = '3d');
  ax.plot(pcs[:,0], pcs[:,1], pcs[:,2], 'k');
  ax.scatter(pcs[:,0], pcs[:,1], pcs[:,2], 'bo', c = range(len(pcs[:,0])), cmap = plt.cm.Spectral );
  plt.xlabel('PCA1'); plt.ylabel('PCA2');
  ax.set_zlabel('PCA3');
  plt.subplot(2,3,3);
  plt.plot(results.mu)
  plt.title('mean');
  plt.subplot(2,3,6);
  plt.plot(np.cumsum(results.fracs), 'r')
  plt.title('variance explained')
  plt.tight_layout();

  return results;
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号