Repository: scverse/scanpy

Issue:
sc.pl.scatter for var
I get the following error when trying to use sc.pl.scatter to plot gene expression, with use_raw=False. I am using sc.pl.scatter instead of sc.pl.umap, .tsne, etc.,  because of the need to use custom basis names.
```
  File "/opt/Python/3.6.5/lib/python3.6/site-packages/scanpy/plotting/_anndata.py", line 118, in scatter
    ax=ax)
  File "/opt/Python/3.6.5/lib/python3.6/site-packages/scanpy/plotting/_anndata.py", line 390, in _scatter_obs
    c = adata.raw.obs_vector(key, layer=layers[2])
TypeError: obs_vector() got an unexpected keyword argument 'layer'
```

The following snippet is copied from `_scatter_obs()` in /scanpy/plotting/_anndata.py
``` python
        # coloring according to gene expression
        elif (use_raw
              and adata.raw is not None
              and key in adata.raw.var_names):
            c = adata.raw.obs_vector(key)
        elif key in adata.var_names:
            c = adata.raw.obs_vector(key, layer=layers[2])
```
Should line 390 be c = adata.obs_vector(key, layer=layers[2]) since it is handling the case when use_raw==False and adata.raw.obs_vector does not take layer as argument.


Discussion:
Thanks for the bug report! That sounds totally right, would you mind submitting a PR to fix that?
@coh-racng I would like to add that for your specific intention the best way is to load the `plot_scatter` function that accepts `basis` as parameter and works well with layers.

The code should be:
```PYTHON
from scanpy._plotting.scatterplots import plot_scatter`
plot_scatter(adata, basis='<name>'....)
```

@ivirshup, @falexwolf  I think we should add `plot_scatter` to the API maybe renaming it `plot_embedding` to help users like @coh-racng. Currently we have two different ways to make scatter plots: One for embeddings (`plot_scatter`) and other more generic for obs and vars (`sc.pl.scatter`) that accepts `x` and `y` parameters.

Resolving patch:
diff --git a/scanpy/plotting/_anndata.py b/scanpy/plotting/_anndata.py
--- a/scanpy/plotting/_anndata.py
+++ b/scanpy/plotting/_anndata.py
@@ -387,7 +387,7 @@ def _scatter_obs(
               and key in adata.raw.var_names):
             c = adata.raw.obs_vector(key)
         elif key in adata.var_names:
-            c = adata.raw.obs_vector(key, layer=layers[2])
+            c = adata.obs_vector(key, layer=layers[2])
         elif is_color_like(key):  # a flat color
             c = key
             colorbar = False


Test patch:
diff --git a/scanpy/tests/test_plotting.py b/scanpy/tests/test_plotting.py
--- a/scanpy/tests/test_plotting.py
+++ b/scanpy/tests/test_plotting.py
@@ -328,6 +328,22 @@ def test_scatterplots(image_comparer):
     sc.pl.umap(pbmc, color=['1', '2', '3'], gene_symbols="numbers", show=False)
     save_and_compare_images('master_umap_symbols')
 
+def test_scatter_raw(tmp_path):
+    pbmc = sc.datasets.pbmc68k_reduced()[:100].copy()
+    raw_pth = tmp_path / "raw.png"
+    x_pth = tmp_path / "X.png"
+
+    sc.pl.scatter(pbmc, color="HES4", basis="umap", use_raw=True)
+    plt.savefig(raw_pth, dpi=60)
+    plt.close()
+
+    sc.pl.scatter(pbmc, color="HES4", basis="umap", use_raw=False)
+    plt.savefig(x_pth, dpi=60)
+    plt.close()
+
+    comp = compare_images(str(raw_pth), str(x_pth), tol=5)
+    assert "Error" in comp, "Plots should change depending on use_raw."
+
 def test_scatter_specify_layer_and_raw():
     pbmc = sc.datasets.pbmc68k_reduced()
     pbmc.layers["layer"] = pbmc.raw.X.copy()