Skip to content

Gene expression color legends and gene names #1913

Description

@gokceneraslan

I have two suggestions/questions about dot/matrix plots:

1- If standard_scale='var' is given, we can write Mean expression\nin group\n(min-max scaled) on the color legend to be more accurate about what is being displayed.

2- People/journals usually expect gene names to be written with italicized characters (don't ask why, see https://en.wikipedia.org/wiki/Gene_nomenclature). So I was wondering if we can simply do that in the plots. One important thing to consider is whether this is organism-dependent. I guess it's not but would be cool to discuss.

Activity

  1. ivirshup commented on Jul 1, 2021

    @ivirshup
    Member

    Relevant discussion for 1.: #1757

    For 2., I believe this is currently possible like this:

    import scanpy as sc
    
    genes = list(pbmc.uns["rank_genes_groups"]["names"][0])
    ret = sc.pl.dotplot(pbmc, genes[::-1], groupby="louvain", show=False)
    ax = ret["mainplot_ax"]
    x_labels = ax.get_xticklabels()
    [l.set_fontstyle("italic") for l in x_labels]
    ax.set_xticklabels(x_labels)
    plt.show()

    But this is a pain.

    Should we just be splatting a passed dict into dot_ax.set_xticklabels?

  2. gokceneraslan commented on Jul 1, 2021

    @gokceneraslan
    ContributorAuthor

    Relevant discussion for 1.: #1757

    Cool, totally forgot about it.

    Should we just be splatting a passed dict into dot_ax.set_xticklabels?

    That would be much more convenient, absolutely. How would the API look like e.g. sc.pl.dotplot(pbmc, ..., gene_font_style='italic')?

  3. gokceneraslan commented on Jul 1, 2021

    @gokceneraslan
    ContributorAuthor

    or set_figure_params(gene_font_style='italic'), which changes it in all/most plots where gene names are written?

  4. ivirshup commented on Jul 2, 2021

    @ivirshup
    Member

    I was thinking more like:

    sc.pl.dotplot(
        ...,
        var_ticklabels_kwargs={
            "fontstyle": "italic",
            ... 
        },
    )

    With an internal:

    var_ticklabels_params = {"rotation": 90, "ha": 'center', "minor": False}
    var_ticklabels_params.update(var_ticklabels_kwargs}
    
    dot_ax.set_xticklabels(var_names, **var_ticklabels_params)
  5. gokceneraslan commented on Jul 2, 2021

    @gokceneraslan
    ContributorAuthor

    Hmm ok, I mean that'd work too, I guess this is more like the difference between programmer's view and practitioner's view 😄

    This is definitely more flexible and cleaner in terms of API design, but if we imagine a notebook with e.g. five sc.pl.dotplot calls, wouldn't it be painful to write this for each call (and memorize)? There are two reasons I suggested set_figure_params

    1. It already has all the tricks to make figures more publication-ready e.g. rasterization, Arial font etc.
    2. Italicized gene names is likely going to be a session-wide (or project-wide) decision, where one would use it in all figures not just in one, which brings us to the importance of conciseness.

    Last suggestion is like theme(axis_text_x=element_text(angle=90, hjust=1)) kind of argument but rotation=90 also works 😃 Anyway, my two cents, happy with any option that achieves this, the community will appreciate it I think.

  6. ivirshup commented on Jul 5, 2021

    @ivirshup
    Member

    if we imagine a notebook with e.g. five sc.pl.dotplot calls

    To me, italicizing the genes is more of a "customizing plots for publication" than "looking at data", so I think it's okay for it to have some extra steps as it happens less often. I personally have used illustrator for this kind of step. Alternatively, I tend to have functions like:

    def customized_dotplot(adata, ..., dotplot_kwargs={}):
        ...  # Preprocess data, maybe add some fields
        ret = sc.pl.dotplot(adata, show=False, ..., **dotplot_kwargs)
        ...  # do additional things

    That said, I'm not against also having a global config for it, I would just want to see the structure for handling this global config for extra setting options sketched out in more detail. Also a PR implementing it 😉.

    Last suggestion is like theme(axis_text_x=element_text(angle=90, hjust=1))

    I do think it would make sense to have this outside of set_figure_params. set_figure_params does some global setting through the matplotlib config. Were you thinking of this as DotPlot(...).theme(...) or sc.settings.theme(...)? Maybe both, with the method overriding the config?

    1. I don't really like that set_figure_params modifies plots not generated by scanpy
    2. matplotlib doesn't have a concept of the "variable axis", so we'd have to handle this ourselves.
  7. gokceneraslan commented on Jul 7, 2021

    @gokceneraslan
    ContributorAuthor

    To me, italicizing the genes is more of a "customizing plots for publication" than "looking at data", so I think it's okay for it to have some extra steps as it happens less often. I personally have used illustrator for this kind of step.

    I disagree very much :) First of all I didn't say that these 10 dotplots are for "looking at data," most of them are indeed for a paper (we can count the number of dotplots in sc papers, if we want to have a more accurate estimate of the time cost) and all of them need to be edited in a pdf editing software. Once the preprint is out, I can write in this post which dotplots I am talking about, how many there are in reality and how much time it took us to manually edit such minor things that can be easily addressed in the plotting code 😄

    What we are discussing is maybe a minor thing here, but if we can minimize the dependency on Illustrator (which is a pricey proprietary software with a highly unintuitive interface in my very subjective opinion) to make publication-ready figures, I think it's a HUGE plus for the community. I think this is related to the philosophy of scanpy. To sum it up in a broader context, I think enabling people to have high-quality, publication-ready figures without mastering matplotlib and/or Illustrator must be one of the top items of the scanpy constitution :)

    I know many colleagues who already nicely memorized the entire scanpy API but asking them also to know bits and pieces of a beast like mpl might be too much IMO. Based on your final suggestion, I can imagine myself trying to remember "Was it var_ticklabels_kwargs={"fontstyle": "italic"} or var_ticklabels_kwargs={"font_style": "italic"} or var_ticklabels_kwds={"fontstyle": "italic"} or ticklabels_var_kwargs={"fontstyle": "italic"} etc. I even spend 45 seconds everyday to remember this damn thing here plt.rcParams["figure.figsize"] :)

    I don't really like that set_figure_params modifies plots not generated by scanpy

    I totally understand this from the coding and engineering perspective, very ugly and violates several principles of good design. But on the other hand, it makes the life of many practitioners easier by setting the plotting config early on in a "Scanpy notebook session", which is clearly created to do research on single-cell genomics with scanpy, without rerunning things several times. For example, I use plotnine sometimes for publications too, but I hate writing theme(text=element_text(family='Arial')) every time I make a figure. plotnine is a general-purpose plotting library so it's not their problem, but people use Scanpy for both data exploration AND publications. So I think we can do better than that.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions