Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scv.pl.velocity_embedding_stream does not work with right_margin specified #765

Open
seigfried opened this issue Dec 2, 2021 · 2 comments
Labels
bug Something isn't working plotting Plotting-related

Comments

@seigfried
Copy link

seigfried commented Dec 2, 2021

Hi could you please help? I tried to make a velocity_embedding_stream plot and the dots get cut on all four sides. I will try to list down the issues I faced

Issue 1 : Dots getting truncated on all four sides
image

Issue 2 : Since dots were truncated, I thought that increasing the margins would help. I tried ?scv.pl.velocity_embedding_stream and I saw the functions left_margin and right_margin. However, when I tried using either of them, I got an error.
...

# paste your code here, if applicable
import scvelo as scv
import pandas as pd
import matplotlib as mpl
import loompy

adata = scv.read("velocity.loom", cache=True)
adata.var_names_make_unique
adata2 = scv.read("scRNAseq.h5ad")

adata3 = scv.utils.merge(adata,adata2)
scv.pp.filter_and_normalize(adata3, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata3, n_pcs=30, n_neighbors=30)
scv.tl.velocity(adata3)
scv.tl.velocity_graph(adata3)

import matplotlib.pyplot as plt
plt.rcParams.update({'lines.markersize' : '15'})

# Snippet for Issue 1
scv.pl.velocity_embedding_stream(adata3, color_map=mpl.cm.Reds, legend_loc="right",
                                 color="leiden", basis='umap', fontsize=20, dpi=300, figsize=[8,8])

# Snippet for Issue 2
scv.pl.velocity_embedding_stream(adata3, color_map=mpl.cm.Reds, legend_loc="right",
                                 right_margin=0.2, color="leiden", basis='umap', fontsize=20, dpi=300, figsize=[8,8])
Error output
# paste the error output here, if applicable
AttributeError                            Traceback (most recent call last)
<ipython-input-36-de7cf880ac12> in <module>
      2 plt.rcParams.update({'lines.markersize' : '15'})
      3 
----> 4 scv.pl.velocity_embedding_stream(adata3, color_map=mpl.cm.Reds, legend_loc="right",
      5                                  right_margin=0.2, color="Specific_CellType", basis='umap', fontsize=20, dpi=300, figsize=[8,8])
      6 #scv.pl.velocity_embedding_stream(adata3, color_map=mpl.cm.Reds, color="leiden", basis='umap',

~\Anaconda3\envs\Velocyto\lib\site-packages\scvelo\plotting\velocity_embedding_stream.py in velocity_embedding_stream(adata, basis, vkey, density, smooth, min_mass, cutoff_perc, arrow_color, linewidth, n_neighbors, recompute, color, use_raw, layer, color_map, colorbar, palette, size, alpha, perc, X, V, X_grid, V_grid, sort_order, groups, components, legend_loc, legend_fontsize, legend_fontweight, xlabel, ylabel, title, fontsize, figsize, dpi, frameon, show, save, ax, ncols, **kwargs)
    214 
    215         size = 8 * default_size(adata) if size is None else size
--> 216         ax = scatter(
    217             adata,
    218             layer=layer,

~\Anaconda3\envs\Velocyto\lib\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)
    593                         kwargs["s"] = np.array(kwargs["s"])[order]
    594 
--> 595             smp = ax.scatter(
    596                 x, y, c=c, alpha=alpha, marker=".", zorder=zorder, **kwargs
    597             )

~\Anaconda3\envs\Velocyto\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
   1350     def inner(ax, *args, data=None, **kwargs):
   1351         if data is None:
-> 1352             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1353 
   1354         bound = new_sig.bind(ax, *args, **kwargs)

~\Anaconda3\envs\Velocyto\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
   4575                 )
   4576         collection.set_transform(mtransforms.IdentityTransform())
-> 4577         collection.update(kwargs)
   4578 
   4579         if colors is None:

~\Anaconda3\envs\Velocyto\lib\site-packages\matplotlib\artist.py in update(self, props)
   1060                     func = getattr(self, f"set_{k}", None)
   1061                     if not callable(func):
-> 1062                         raise AttributeError(f"{type(self).__name__!r} object "
   1063                                              f"has no property {k!r}")
   1064                     ret.append(func(v))

AttributeError: 'PathCollection' object has no property 'right_margin'
Versions
# paste the ouput of scv.logging.print_versions() here
scvelo==0.2.3  scanpy==1.7.2  anndata==0.7.6  loompy==3.0.6  numpy==1.20.3  scipy==1.6.3  matplotlib==3.4.1  sklearn==0.24.2  pandas==1.2.4  
@seigfried seigfried added the bug Something isn't working label Dec 2, 2021
@WeilerP
Copy link
Member

WeilerP commented Dec 2, 2021

@seigfried, two things:

  1. Would please update to the latest package versions and check that the problem persists?
  2. Could you please provide an exemplary code snippet I can simply copy and paste? (For example using the Pancreas dataset used in the scvelo paper.)

Using the pancreas dataset, I can reproduce the problem regarding right_margin but not the cutoff.

@WeilerP WeilerP changed the title velocity_embedding_stream right_margin left_margin scv.pl.velocity_embedding_stream does not work with right_margin specified Dec 2, 2021
@WeilerP
Copy link
Member

WeilerP commented Dec 2, 2021

@seigfried, two things:

  1. Would please update to the latest package versions and check that the problem persists?
  2. Could you please provide an exemplary code snippet I can simply copy and paste? (For example using the Pancreas dataset used in the scvelo paper.)

Using the pancreas dataset, I can reproduce the problem regarding right_margin but not the cutoff.

@seigfried, nevermind, I managed to reproduce the cutoff problem. I'll open a separate issue, comment a bit more there and investigate it ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plotting Plotting-related
Projects
None yet
Development

No branches or pull requests

2 participants