Skip to content

Avoid argument explosion in plotting functions #956

Description

@fidelram
  • 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)

Activity

  1. LuckyMD commented on Dec 17, 2019

    @LuckyMD
    Contributor

    I love this! Question from my side would be how to best make docs for this. Might fragment the documentation too much if we're not careful with this.

  2. fidelram commented on Dec 18, 2019

    @fidelram
    CollaboratorAuthor

    With respect to documentation: each plotting function becomes a module with well described functions. An example is the styling of pandas DataFrames (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.io.formats.style.Styler.html)

  3. LuckyMD commented on Dec 18, 2019

    @LuckyMD
    Contributor

    That looks really good!

  4. gokceneraslan commented on Dec 19, 2019

    @gokceneraslan
    Contributor

    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?

  5. LuckyMD commented on Dec 19, 2019

    @LuckyMD
    Contributor

    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.

  6. fidelram commented on Jan 16, 2020

    @fidelram
    CollaboratorAuthor

    @gokceneraslan indeed styling needs to be addressed and your solution seems quite interesting however, I don't know how complicated is to implement something like this.

    My suggestion would be to try the chaining first at least with some functions to see how practical is this. Maybe @VolkerBergen that is revising the scatter plots can try some initial steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions