question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid argument explosion in plotting functions

See original GitHub issue
  • Additional function parameters / changed functionality / changed defaults?
  • New analysis tool: A simple analysis tool you have been using and are missing in sc.tools?
  • New plotting function: A kind of plot you would like to seein sc.pl?
  • External tools: Do you know an existing package that should go into sc.external.*?
  • Other?

To reduce the number of arguments that are passed to plotting functions and to agrupate them by type I was considering the following example syntax:

sc.pl.umap(adata, color='clusters').scatter_outline(width=0.1)
                                   .legend(loc='on data',  outline=1)
                                   .add_edges(color='black', width=0.1)

or

sc.pl.dotplot(adata, ['gene1', 'gene2'], groupby='clusters')
                     .add_dendrogram(width=0.4,color='grey')
                     .swap_axes()
                     .dot_size_legend(title='fraction', location='left')

Any comments? (I am not sure how to implement something like this)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
LuckyMDcommented, Dec 19, 2019

I like the idea and I see your point, however I wonder how intuitive the concept of a style is for beginners. Also you’d have to know exactly what you are looking to plot during your analysis to set up a style for all plots for the future (e.g. do you need arrows? Will you use a marker gene dotplot?). Context managers definitely look clean (I love that I have my own ^^), but it would make things a bit more difficult for beginners to get an intuitive feel for scanpy.

1reaction
gokceneraslancommented, Dec 19, 2019

I support the idea of tidying up plotting arguments. I think there are mainly two problems. 1) the high number of plotting arguments 2) lack of reusability of plotting “styles”.

Chaining looks really cool and improves 1). Also, it logically partitions the plotting arguments. However, it doesn’t solve 2). In other words, if we plot two figures, we’ll need to copy the entire thing, and it’ll be very verbose:

sc.pl.umap(adata, color='clusters').scatter_outline(width=0.1)
                                   .legend(loc='on data',  outline=1)
                                   .add_edges(color='black', width=0.1)

sc.pl.umap(adata2, color='fluffy').scatter_outline(width=0.1)
                                  .legend(loc='on data',  outline=1)
                                  .add_edges(color='black', width=0.1)

One thing that comes to mind for reusability is to store the result of the chain somewhere and, well, reuse it:

style = sc.pl.styles.scatter_outline(width=0.1)
                    .legend(loc='on data',  outline=1)
                    .add_edges(color='black', width=0.1)

# using simple arguments, similar to https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/lmeControl.html
sc.pl.umap(adata, color='clusters', style=style)
sc.pl.umap(adata2, color='fluffy', style=style)

# using context managers, similar to https://seaborn.pydata.org/tutorial/aesthetics.html#temporarily-setting-figure-style
with style:
    sc.pl.umap(adata, color='clusters')
    sc.pl.umap(adata2, color='fluffy')

# overriding an existing style object
with style.legend(fontsize=12):
    sc.pl.umap(adata, color='clusters')
    sc.pl.umap(adata2, color='fluffy')

# or use predefined styles (?)
with sc.pl.style('malte'):
    sc.pl.umap(adata, color='clusters')
    sc.pl.umap(adata2, color='fluffy')

WDYT?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Avoid Exploding Gradients With Gradient Clipping
Exploding gradients can be avoided in general by careful configuration of the network model, such as choice of small learning rate, scaled ...
Read more >
ggplot2 plot function with several arguments - Stack Overflow
I would like to plot, in one single plot, all results of this function for a range of arguments d and p. In...
Read more >
plotrix: Various Plotting Functions
The two justification arguments, 'xjust' and 'yjust' are the same as in the 'legend' ... the two sections of the plot is probably...
Read more >
[WIP] Dotplot (aka bubble plot) improvements by fidelram · Pull ...
The dotplot functionality has been separated from the main function. ... of parameters as suggested in Avoid argument explosion in plotting functions #956....
Read more >
Combinatorial explosion - Wikipedia
In mathematics, a combinatorial explosion is the rapid growth of the complexity of a problem due to how the combinatorics of the problem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found