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

Legend alignment in dotplot #1103

Closed
LuckyMD opened this issue Mar 15, 2020 · 6 comments
Closed

Legend alignment in dotplot #1103

LuckyMD opened this issue Mar 15, 2020 · 6 comments
Labels

Comments

@LuckyMD
Copy link
Contributor

LuckyMD commented Mar 15, 2020

Hey!
The color bar and legend don't seem to align well... might be because i'm subsetting the object.

Here is what happens (reproducible example and my plot, which is even stranger with legend overlap):

Screenshot 2020-03-15 at 13 09 33

Screenshot 2020-03-15 at 13 02 52

import scanpy as sc
adata = sc.datasets.pbmc68k_reduced()
sc.pl.dotplot(adata[adata.obs.bulk_labels.isin(['Dendritic', 'CD14+ Monocyte', 'CD4+/CD25 T Reg']),], var_names=['HES4', 'TNFRSF4', 'SSU72'], groupby='bulk_labels', figsize=(8,8))

Versions:

scanpy==1.4.5.1 anndata==0.7.1 umap==0.3.10 numpy==1.18.1 scipy==1.4.1 pandas==1.0.1 scikit-learn==0.22.2 statsmodels==0.11.1 python-igraph==0.8.0 louvain==0.6.1

Also, matplotlib is 3.1.3

@ivirshup
Copy link
Member

Huh. As far as I can tell, this seems to happen only if there are 3 or less groups.

@ivirshup
Copy link
Member

@LuckyMD
Copy link
Contributor Author

LuckyMD commented Mar 17, 2020

This seems like a bad idea, no? It also seems to throw off the legend other than the colorbar.

@fidelram
Copy link
Collaborator

In #1127 I changed the way that the colorbar and size legend are plotted and should solve this problem.

@gabriellayi
Copy link

Hi, I have the same problem, sorry that I just started learning python, so I don't really understand some of the improvements and I also tried some of them, it didn't work.
Could you please let me know what kind of solution will be good for this issue?

Thanks!
Screen Shot 2020-05-24 at 17 43 08
Screen Shot 2020-05-24 at 17 43 42

Yi

@fidelram
Copy link
Collaborator

This is being fixed in #1210

for the time being you can try to set dendrogram=False or you can install the branch with the fix.

fidelram added a commit that referenced this issue Jun 29, 2020
 * Unifies common code between `dotplot`, `matrixplot` and `stacked_violin` plots while adding flexibility to the plots. sc.pl.dotplot`, `sc.pl.matrixplot` and `sc.pl.stacked_violin` methods had been transformed into wrappers for the new `DotPlot`, `MatrixPlot` and `StackedVioling` classes. Accessing the new classes directly allows further fine tuning of the plots. 

* The new plot classes are all descendants of `BasePlot` class that captures the common code. The design of the classes follows the method chaining (as found in Pandas or Altair). This allows the addition of independent features (via well documented methods) to the plot without increasing the number parameters of a single function. This was first suggested here #956. All objects have consistent functions for `legend`, to set up titles and width, `style()` to set visual parameters specific to each plot like colormap, edge color, linewidth. `swap_axes` to transpose the figure, `add_dendrogram` with options to change the with of the dendrogran and `add_total` tho show a bar plot of the total number of cells per category. Also includes options to sort the categories.

 * Previous functionality is maintained but plots will look slightly different.

 *  This commit addresses issues from #979 and #1103 related to `sc.pl.dotplot` 

 * Now is possible to plot fold changes, log fold changes and p-values from `sc.tl.rank_genes_groups` as suggested in #562

Specific changes:
**all figures**:
 * Set a title to the image. 
 * Pass an `axe` where to plot the image.
 * Return a dictionary of axes for further manipulation
 * using `return_fig` the plot object can be used to adjust the proportions to the legend and other visual aspects can be fine tuned.
 * a bar plot with the totals per category can be added. This will align at the left of the image if the categories are plotted in rows or at the top if they are plotted in columns.
 * legend can be removed
 * `groupby` can be a list of categories. 

**dotplot**
 * Improved the colorbar and size legend for dotplots. Now the colorbar and size have titles, which can be modified using the `colorbar_title` and `size_title` arguments. They also align at the bottom of the image and do not shrink if the dotplot image is smaller.
 * Plot genes in rows and categories in columns (swap_axes).
 * Using the DotPlot object the dot_edge_color and line width can be set up, a grid added as well as several other features
 * `sc.pl.rank_genes_groups_dotplot` can now plot `pvals` and `log fold changes`

**matrixplot**
 * added title for colorbar and positioned as in dotplot
 * `sc.pl.rank_genes_groups_matrixplot` can now plot `pvals` and `log fold changes`

**stacked_violin**
 *  violin colors can be colored based on average gene expression as in dotplots
 * made the linewidth of the violin plots smaller.
 * removed the tics for the y axis as they tend to overlap with each other. Using the `style` method they can be visualized.

**other**
* `sc.pl.heatmap` and `sc.pl.trackplots` now return a dictionary of axes when `show=False` as for the other plots.
* now 'interpolation' can be passed as parameter for `sc.pl.heatmap`
@ivirshup ivirshup closed this as completed Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants