theislab / scvelo_notebooks

31 stars 12 forks source link

AttributeError in scv.pl.velocity_embedding_stream #6

Open musikutiv opened 1 year ago

musikutiv commented 1 year ago

recently I get this error when I try to plot velocity_embedding_stream on the pancreas dataset anndata 0.9.1 scvelo 0.2.5 session_info 1.0.0 Python 3.10.10

scv.pl.velocity_embedding_stream(adata, basis='umap') computing velocity embedding finished (0:00:00) --> added 'velocity_umap', embedded velocity vectors (adata.obsm)

AttributeError Traceback (most recent call last) Cell In[9], line 1 ----> 1 scv.pl.velocity_embedding_stream(adata, basis='umap')

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/scvelo/plotting/velocity_embedding_stream.py:252, in velocity_embedding_stream(adata, basis, vkey, density, smooth, min_mass, cutoff_perc, arrow_color, arrow_size, arrow_style, max_length, integration_direction, 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) 249 ax.streamplot(X_grid[0], X_grid[1], V_grid[0], V_grid[1], stream_kwargs) 251 size = 8 * default_size(adata) if size is None else size --> 252 ax = scatter( 253 adata, 254 layer=layer, 255 color=color, 256 size=size, 257 title=title, 258 ax=ax, 259 zorder=0, 260 **scatter_kwargs, 261 ) 262 if save is True: 263 save = "embedding_stream"

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/scvelo/plotting/scatter.py:668, 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, legend_align_text, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_margin, add_outline, outline_width, outline_color, n_convolve, smooth, normalize_data, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, **kwargs) 666 if not (add_outline is None or g_bool is None): 667 groups = add_outline --> 668 set_legend( 669 adata, 670 ax, 671 color, 672 legend_loc, 673 scatter_array, 674 legend_fontweight, 675 legend_fontsize, 676 legend_fontoutline, 677 legend_align_text, 678 groups, 679 ) 680 if add_density: 681 plot_density(x, y, add_density, ax=ax)

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/scvelo/plotting/utils.py:555, in set_legend(adata, ax, value_to_plot, legend_loc, scatter_array, legend_fontweight, legend_fontsize, legend_fontoutline, legend_align_text, groups) 553 legend_fontoutline = 1 554 obs_vals = adata.obs[value_to_plot] --> 555 obs_vals.cat.categories = obs_vals.cat.categories.astype(str) 556 color_keys = adata.uns[f"{value_to_plot}_colors"] 557 if isinstance(color_keys, dict):

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/pandas/core/base.py:178, in NoNewAttributesMixin.setattr(self, key, value) 172 if getattr(self, "__frozen", False) and not ( 173 key == "_cache" 174 or key in type(self).dict 175 or getattr(self, key, None) is not None 176 ): 177 raise AttributeError(f"You cannot add any new attribute '{key}'") --> 178 object.setattr(self, key, value)

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/pandas/core/accessor.py:99, in PandasDelegate._add_delegate_accessors.._create_delegator_property.._setter(self, new_values) 98 def _setter(self, new_values): ---> 99 return self._delegate_property_set(name, new_values)

File ~/miniconda3/envs/scVelo/lib/python3.10/site-packages/pandas/core/arrays/categorical.py:2460, in CategoricalAccessor._delegate_property_set(self, name, new_values) 2459 def _delegate_property_set(self, name, new_values): -> 2460 return setattr(self._parent, name, new_values)

AttributeError: can't set attribute 'categories'

anne-marie-lyne commented 11 months ago

I have the same issue on my own data, did you figure out a fix? I can plot fine using velocity_embedding_stream if I don't want to use the 'color' parameter, but if I do I get the above error. Thanks