theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
409 stars 102 forks source link

figure params in notebooks different #355

Closed giovp closed 3 years ago

giovp commented 3 years ago

Hi,

I'm working through this notebook and noticed several things that are not consistent anymore: https://scvelo.readthedocs.io/DynamicalModeling.html

For instance, line 15 through an error(rightly so)

for cluster in adata.obs.cluster.cat.categories:
    scv.pl.scatter(adata, df[cluster][:5], ylabel=cluster, frameon=False)
Details ``` --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in 3 for cluster in adata.obs["leiden_1.0"].cat.categories.values: 4 print(cluster) ----> 5 scv.pl.scatter(adata, df[str(cluster)][:5], ylabel=cluster, frameon=False) ~/miniconda3/envs/cellrank/lib/python3.8/site-packages/scvelo/plotting/scatter.py in scatter(adata, basis, x, y, vkey, color, use_raw, layer, color_map, colorbar, palette, size, alpha, linewidth, linecolor, perc, groups, sort_order, components, projection, legend_loc, legend_loc_lines, legend_fontsize, legend_fontweight, legend_fontoutline, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_outline, outline_width, outline_color, n_convolve, smooth, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, **kwargs) 149 multikey = unique(multikey) # take unique set if no more than one multikey 150 if len(multikey) > 20: --> 151 raise ValueError("Please restrict the passed list to max 20 elements.") 152 if ax is not None: 153 logg.warn("Cannot specify `ax` when plotting multiple panels.") ValueError: Please restrict the passed list to max 20 elements. ```

df.iloc should be used. Can't really judge which pandas version cause logging doesn't show.

Also, the same figure looks something like this: image

and not with the prettycoloring per cluster. This despite setting:

scv.settings.set_figure_params('scvelo')  # for beautified visualization

Versions:

scanpy==1.7.0rc2.dev26+gdd50040a anndata==0.7.5 umap==0.4.6 numpy==1.20.1 scipy==1.6.0 pandas==1.2.2 scikit-learn==0.24.1 statsmodels==0.12.2 python-igraph==0.8.3 leidenalg==0.8.3

Running scvelo 0.2.3 (python 3.8.6) on 2021-02-15 18:01.

this is really a minor thing but just wanted to report it.

Also, the parallel recover_dynamics is S I C K !

VolkerBergen commented 3 years ago

Thanks @giovp, I think simple subsetting to a specified column does not require iloc. What do you have in df[cluster][:5] - how is it possible that it returns more than 20 vals?

For the coloring, have you annotated your obs['clusters'] or computed tl.louvain?

giovp commented 3 years ago

Thanks for quick reply @VolkerBergen !!! again, really minor thing. So in df[cluster][:5] I have all the highvar genes (for whichI computed diff kinetics). For obs['clusters'] of course yes have annotated and colors are uns. I get the correct behaviour by setting color

scv.pl.scatter(
        adata,
        df[str(cluster)].iloc[:5],
        ylabel=cluster,
        frameon=False,
        color="leiden_1.0",
    )
WeilerP commented 3 years ago

Hm interesting. @giovp, did you use the pancreas dataset or your own? Just ran the notebook in a fresh environment and everything worked as expected. As @VolkerBergen already mentioned, df[cluster][:5] shouldn't cause an issue. Double checked on a couple of examples and it returns the same result as df[cluster].iloc[:5].

Regarding the missing color in the scatter plot: Did you, by any chance, set the figure params, e.g., also in scanpy? I previously encountered problems / inconsistencies when setting both.

WeilerP commented 3 years ago

Hm interesting. @giovp, did you use the pancreas dataset or your own? Just ran the notebook in a fresh environment and everything worked as expected. As @VolkerBergen already mentioned, df[cluster][:5] shouldn't cause an issue. Double checked on a couple of examples and it returns the same result as df[cluster].iloc[:5]. Regarding the missing color in the scatter plot: Did you, by any chance, set the figure params, e.g., also in scanpy? I previously encountered problems / inconsistencies when setting both.

@giovp, do you have an update on this so that we can investigate what exactly caused the error?

giovp commented 3 years ago

Hi @WeilerP , sorry for being late. Actually I did not manage to nail it down and could have most likely been an issue with anndata on my side. I will close this for now and re open it if I encounter it again. SOrry for not following it up. Thank you!