Repository: scverse/scanpy

Issue:
Scatter plot of numerical observation with missing data
I have a dataset for which I have an observation that is only available for some cells. When I make a scatter plot that I color code for this observation not all cells are plotted:
```python
import random
import scanpy as sc

adata = sc.datasets.blobs()
adata.obs['property'] = 630 * [float("nan")] + 10 * [1] 

sc.tl.pca(adata)
sc.pl.pca(adata, color='property', size=50)
```
While this should plot 10 cells it only shows one cell:
![image](https://user-images.githubusercontent.com/7300030/54540172-caa1c700-4997-11e9-946e-01c1e04dd2d2.png)
I can get the plot I want by filtering cells first:
```python
sc.pl.pca(adata[adata.obs['property'] == 1], color='property', size=50)
```
![image](https://user-images.githubusercontent.com/7300030/54540221-e60cd200-4997-11e9-9b53-e9917bd01c59.png)
Would you agree that scanpy should plot all cells that have a valid observation?


Discussion:
That's very strange. I will take a look

On Mon, Mar 18, 2019 at 4:09 PM Fabian Rost <notifications@github.com>
wrote:

> I have a dataset for which I have an observation that is only available
> for some cells. When I make a scatter plot that I color code for this
> observation not all cells are plotted:
>
> import randomimport scanpy as sc
>
> adata = sc.datasets.blobs()
> adata.obs['property'] = 630 * [float("nan")] + 10 * [1]
>
> sc.tl.pca(adata)
> sc.pl.pca(adata, color='property', size=50)
>
> While this should plot 10 cells it only shows one cell:
> [image: image]
> <https://user-images.githubusercontent.com/7300030/54540172-caa1c700-4997-11e9-946e-01c1e04dd2d2.png>
> I can get the plot I want by filtering cells first:
>
> sc.pl.pca(adata[adata.obs['property'] == 1], color='property', size=50)
>
> [image: image]
> <https://user-images.githubusercontent.com/7300030/54540221-e60cd200-4997-11e9-9b53-e9917bd01c59.png>
> Would you agree that scanpy should plot all cells that have a valid
> observation?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/theislab/scanpy/issues/536>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AEu_1X3Le-1usPntk050roRY9vedXEHHks5vX6wMgaJpZM4b6BYA>
> .
>

I just add the versions I used:
```python
sc.logging.print_versions()

scanpy==1.4 anndata==0.6.18 numpy==1.15.4 scipy==1.2.0 pandas==0.24.2 scikit-learn==0.20.2 statsmodels==0.9.0 python-igraph==0.7.1 louvain==0.6.1 
```
the problem is that at some point the code calls np.argsort on a
pandas.Series and this returns -1 for NaN values. I will submit a PR to fix
this. Meanwhile, simpy plot as follows: sc.pl.pca(adata, color='property',
size=50, sort_order=False)

On Tue, Mar 19, 2019 at 11:45 AM Fabian Rost <notifications@github.com>
wrote:

> I just add the versions I used:
>
> sc.logging.print_versions()
>
> scanpy==1.4 anndata==0.6.18 numpy==1.15.4 scipy==1.2.0 pandas==0.24.2 scikit-learn==0.20.2 statsmodels==0.9.0 python-igraph==0.7.1 louvain==0.6.1
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/theislab/scanpy/issues/536#issuecomment-474301705>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AEu_1b3l_xKITwuZQ-XpENUHSioDqLWLks5vYL_TgaJpZM4b6BYA>
> .
>


Resolving patch:
diff --git a/scanpy/plotting/_tools/scatterplots.py b/scanpy/plotting/_tools/scatterplots.py
--- a/scanpy/plotting/_tools/scatterplots.py
+++ b/scanpy/plotting/_tools/scatterplots.py
@@ -651,7 +651,7 @@ def _get_color_values(adata, value_to_plot, groups=None, palette=None, use_raw=F
                 # that are not in the groups
                 color_vector[~adata.obs[value_to_plot].isin(groups)] = "lightgray"
         else:
-            color_vector = adata.obs[value_to_plot]
+            color_vector = adata.obs[value_to_plot].values
     elif gene_symbols in adata.var.columns:
         if value_to_plot not in adata.var[gene_symbols].values:
             logg.error("Gene symbol {!r} not found in given gene_symbols "


Test patch: