Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvements on plotting functions that use 'groupby' (#1210)
* 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`
- Loading branch information