Skip to content

Figure improvements #369

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

Merged
merged 25 commits into from
Nov 30, 2018
Merged

Figure improvements #369

merged 25 commits into from
Nov 30, 2018

Conversation

fidelram
Copy link
Collaborator

@fidelram fidelram commented Nov 20, 2018

This PR introduces the following changes:

  • swap_axes option was added to pl.matrixplot and pl.heatmap. When swap_axes=True, the x axis contains cells and the y axis contains genes (Figures related to rankings and heatmap could be transposed. #349).
  • added show_genes_labels to pl.heatmap. This allows to have compact heatmaps without overlapping gene labels.
  • added lines to separate categories in pl.heatmap.
  • changed categories colors in pl.heatmap by the colors found in adata.uns
  • removed empty space that was present in different plots
  • added a layer option to specify which layer to use for plotting.
  • added a new visualization called pl.tracksplot.
  • changed if <variable> is True by if <variable> after @flying-sheep remarks.
  • added setup() from matplotlib.testing
  • reduced dpi of test images to 40.
  • added var_groups plot for stacked_violin when swap_axes=True
  • improved layout of stacked_violin (default width and linewidth of violin plots)

As an example, here is how some of the changes look like. I am using the rank_genes_groups_* plots because they contain more visual elements. Further examples can be seen here: https://gist.github.com/fidelram/2289b7a8d6da055fb058ac9a79ed485c

heatmap with swap_axes=True, show_gene_labels=False:
image

matrixplot with swap_axes=True:

image

new tracksplot: Each track contains the var (genes) values sorted and colored according to the categories used:
image

tracksplot using the results of sc.tl.rank_genes_groups:
image

@flying-sheep
Copy link
Member

Wow, this looks great! One remark for future PRs: We’re migrating to a new documentation style using type annotations (see e.g. https://github.com/theislab/scanpy/blob/master/scanpy/tools/louvain.py)

could you use that in future PRs, please? (no need to do it in this one)

@LuckyMD
Copy link
Contributor

LuckyMD commented Nov 20, 2018

This looks amazing!

@fidelram
Copy link
Collaborator Author

@flying-sheep I will be happy to start using the proposed documentation style for future PRs!

Copy link
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job! there’s some duplication going on that should be avoided, otherwise the code looks great and the plots gorgeous!

@falexwolf
Copy link
Member

This is awesome! Thank you, Fidel! 😄

@falexwolf
Copy link
Member

falexwolf commented Nov 20, 2018

edit: moved to #373

@flying-sheep
Copy link
Member

I took this unrelated discussion to its own issue 😃

@fidelram
Copy link
Collaborator Author

fidelram commented Nov 21, 2018

Together with the suggested changes, I am also updating my usual notebook containing examples of all the plots (not yet updated: https://gist.github.com/fidelram/2289b7a8d6da055fb058ac9a79ed485c). However, don't you think that this could be part of a the scanpy tutorials section?

@grst
Copy link
Contributor

grst commented Nov 22, 2018

@fidelram, I really like your plotting gallery! Would be cool to have that as part of the tutorials or even integrated in the main documentation (enhance each plotting function with an example image?)

@flying-sheep
Copy link
Member

OK, my changes in 426f028 didn’t make the tests break!

Do we currently not use the plotting test results?

@falexwolf
Copy link
Member

However, don't you think that this could be part of a the scanpy tutorials section?

Of course, this should become a part of the scanpy tutorials section! That would be awesome! I already asked you for that some time ago. 😉 I'd also start adding calls producing images to the doc pages.

Let me build the core infrastructure for having the tutorials run on readthedocs and adding notebooks containing only code to the scanpy main repo.

If you want, to shortcut, you can make a PR to scanpy_usage and upload your notebook there. Or, equally well, we simply link to your notebook from the tutorials page.

@falexwolf
Copy link
Member

Can I merge this, @fidelram and @flying-sheep?

@fidelram
Copy link
Collaborator Author

Green light on my side to merge.

@flying-sheep
Copy link
Member

See my last comment. After fixing the colormaps in this PR, I didn’t update the images, but the tests still pass. What’s up with that?

@fidelram
Copy link
Collaborator Author

@flying-sheep I think that your changes should produce images that are almost equal to the ones on the tests as your changes simply introduce a different way to get the colormap. Btw, what is the advantage of using ListedColormap and BoundaryNorm instead of LinearSegmentedColormap ?

@fidelram
Copy link
Collaborator Author

@falexwolf I added a PR for the notebook that I have on the gist to the scanpy_usage (scverse/scanpy_usage#9)

@flying-sheep
Copy link
Member

flying-sheep commented Nov 26, 2018

The important part is the BoundaryNorm. We got a really weird selection of colors without it, since the default is to treat the colormap as a linear space. max(vec) gets the last color, min(vec) the first one, and everything else some color between. Using the BoundaryNorm I defined, numbers in [0, len(colors)-1] get the color at the respective index, and everything smaller or bigger would get the first or last color (not ideal, but better than what we had)

I don’t think it really makes a difference, but ListedColormap is a colormap for discrete uses like ours, LinearSegmentedColormap is for interpolating continuous values onto the map.

Before After
before after

In the before pic, we map [0,1,2,3] onto [0;19], which results in [0, 5.75, 10.5, 14.25, 19], and [to_hex(tab20.colors[math.ceil(i)]) for i in [0, 5.75, 10.5, 14.25, 19]] gives us [#1f77b4, #98df8a, #8c564b, #c7c7c7, #9edae5]

@fidelram
Copy link
Collaborator Author

Thanks for the clarification. Your solution guarantees that the same colors present in let's say .uns['louvain_colors'] will be represented accurately. The previous solution would not have achieve that.

@falexwolf
Copy link
Member

Thank you again! I'm merging this. Release prior to this is 1.3.4.

@falexwolf falexwolf merged commit c44ee80 into scverse:master Nov 30, 2018
@fidelram
Copy link
Collaborator Author

fidelram commented Nov 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants