question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with sc.pl.pca when using components

See original GitHub issue

I try to use sc.pl.pca selecting components. According to the documentation the following should work:

import scanpy.api as sc
sc.logging.print_versions()
adata = sc.datasets.blobs()
sc.tl.pca(adata)
sc.pl.pca(adata, components=['1,2', '2,3'])

However, I get an error. The output of the code above is:

scanpy==0+unknown anndata==0.6.9 numpy==1.14.5 scipy==1.1.0 pandas==0.23.4 scikit-learn==0.19.1 statsmodels==0.9.0 python-igraph==0.7.1 louvain==0.6.1 
... storing 'blobs' as categorical

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-4cd21e9edf25> in <module>()
      3 adata = sc.datasets.blobs()
      4 sc.tl.pca(adata)
----> 5 sc.pl.pca(adata, components=['1,2', '2,3'])

~/software/scanpy/scanpy/plotting/tools/__init__.py in pca(adata, color, use_raw, sort_order, alpha, groups, components, projection, legend_loc, legend_fontsize, legend_fontweight, color_map, palette, right_margin, size, title, show, save, ax)
    114         title=title,
    115         show=False,
--> 116         save=False, ax=ax)
    117     utils.savefig_or_show('pca_scatter', show=show, save=save)
    118     if show == False: return axs

~/software/scanpy/scanpy/plotting/anndata.py in scatter(adata, x, y, color, use_raw, layers, sort_order, alpha, basis, groups, components, projection, legend_loc, legend_fontsize, legend_fontweight, color_map, palette, frameon, right_margin, left_margin, size, title, show, save, ax)
    110             show=show,
    111             save=save,
--> 112             ax=ax)
    113     elif x is not None and y is not None:
    114         if ((x in adata.obs.keys() or x in adata.var.index)

~/software/scanpy/scanpy/plotting/anndata.py in _scatter_obs(adata, x, y, color, use_raw, layers, sort_order, alpha, basis, groups, components, projection, legend_loc, legend_fontsize, legend_fontweight, color_map, palette, frameon, right_margin, left_margin, size, title, show, save, ax)
    291     if components is None: components = '1,2' if '2d' in projection else '1,2,3'
    292     if isinstance(components, str): components = components.split(',')
--> 293     components = np.array(components).astype(int) - 1
    294     keys = ['grey'] if color is None else [color] if isinstance(color, str) else color
    295     if title is not None and isinstance(title, str):

ValueError: invalid literal for int() with base 10: '1,2'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fbnrstcommented, Sep 4, 2018

@LuckyMD, thanks for the workaround which indeed helps for now.

1reaction
falexwolfcommented, Sep 4, 2018

Hey @LuckyMD, @fidelram is currently completely rewriting the whole scatter plotting module. So let’s not address this in the current code. But, yes in principle, we should add it so that diffmap and pca behave consistently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with sc.pl.pca when using components #254 - GitHub
I try to use sc.pl.pca selecting components. According to the documentation the following should work: import scanpy.api as sc ...
Read more >
scanpy.pl.pca — Scanpy 1.9.1 documentation - Read the Docs
Scatter plot in PCA coordinates. Use the parameter annotate_var_explained to annotate the explained variance. Parameters. adata : AnnData.
Read more >
Principal Component Analyses (PCA)-based findings ... - Nature
We demonstrate that PCA results can be artifacts of the data and can be easily manipulated to generate desired outcomes. PCA adjustment also ......
Read more >
Importing python modules and loading data
Here, we will be processing the data using principal component analysis (PCA) and selecting a cutoff representing the most informative principal components.
Read more >
Principal Components Analysis - CMU Statistics
In practice, it is faster to use eigenvector-solvers to get all the components at once from v, but this idea is correct in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found