plot.py 文件源码

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

项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码
def plot_nmf(data, analyse = True, n_components = 2):
  """Perform NMF and plot overview of the results"""

  if analyse:
    nmf = sd.NMF(n_components=n_components, init = 'nndsvdar', random_state = 0, solver = 'cd')
    Y = nmf.fit_transform(data)
  else:
    Y = data;
    nmf = None;    

  if n_components is None:
    n_components = 3;

  if n_components == 1:
    plt.subplot(1,3,1);  
    plt.plot(Y);
  elif n_components == 2:
    plt.subplot(1,3,1); 
    plt.scatter(Y[:,0], Y[:,1], c = range(len(Y[:,0])), cmap = plt.cm.Spectral);
  else:
    ax = plt.gcf().add_subplot(1,3,1, projection = '3d');
    ax.scatter(Y[:, 0], Y[:, 1], Y[:,2], c = range(len(Y[:,0])), cmap=plt.cm.Spectral)
  plt.title("nmf")

  if nmf is not None:
    feat = nmf.components_;
    plt.subplot(1,3,2);
    plt.imshow(feat, interpolation = 'none', aspect = 'auto', cmap = 'viridis')
    plt.colorbar(pad = 0.01,fraction = 0.01)
    plt.title('features');

  plt.subplot(1,3,3);
  plt.imshow(Y, interpolation = 'none', aspect = 'auto', cmap = 'viridis')
  plt.colorbar(pad = 0.01,fraction = 0.01)
  plt.title('amplitudes');

  plt.tight_layout();
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号