Repository navigation
Simpler scatter functions - #244
Conversation
|
Could you please add images to scanpy/docs/api? |
|
@flying-sheep Sure, I can add the images as well. But first, I want to know if @falexwolf agrees to continue working on these changes. |
|
This looks good! I'd also say that we should move towards a more transparent code for the scatter plots. It's a result of 1.5 years of subsequently adding features. No good initial plan about that. The only problems I see:
What do you think? |
|
@falexwolf Thanks for the support. I agree that this is not an urgent changes that can quietly be tested. Have you consider having a 'develop' branch were we can put all code like this? As you point out some differences are seen with respect to the shape of the plot when multiple panels are plot. This is mostly due to some code to add space for the colorbar and legends that can overlap nearby figures. Nevertheless, I can further adjust this to get plots that are more similar to the actual ones. I think that the tests are failing because there is a clash between the module and a method called If you don't mind I would slowly start removing redundant code and adding further tests. So, lets keep this PR open. |
|
Apologies for again, the late response @fidel! I married and moved to the US with twin babies last week. And in between, I spilled something over my laptop... Yes, please go ahead and remove redundant code and add further tests. We'll merge this PR eventually. And yes, we can think about a |
|
How about we first merge all of this in a |
|
PS: I updated the seurat-based tutorial and added a few of your plotting functions and a link to your gist. Feel free to update it further! |
…multiple components (eg components=['1,2', '2,3']
|
@falexwolf Can you take a look at the updated gist: https://gist.github.com/fidelram/8b43f786e7519bcfb7ffc0d5ccdbb0fe Most of the previous and new plots are quite similar. For diffmap I see different results but I suspect that there is a bug in the previous code. Also, I don't have any example with arrows. Do you have any? |
|
@falexwolf Do you know a more efficient way to get the value of a single column given the gene name. Currently, I am using: This is easy but not optimal. Any idea? I will start updating the test once we are happy we the new results. |
|
Why is it not optimal, can you be more specific and maybe provide an example? It's supposed to be the canonical way. It should be as fast as it possibly gets. If you have sparse data, it could be worthwhile transforming If there's something to improve here, this would be a top priority for me and I'd immediately fix it. |
falexwolf
left a comment
There was a problem hiding this comment.
I clicked on the wrong button, wanted to comment not review. ;)
| else: | ||
| args_3d = {} | ||
|
|
||
| if adata.raw is None and use_raw is True: |
There was a problem hiding this comment.
Since a while, the convention in all the plotting functions is that use_raw=None is the default (you might remember that I asked you for your opinion a few weeks back). Hence, you can throw an error if someone sets use_raw=True and .raw is None.
There was a problem hiding this comment.
I modify this to adjust to the convention.
|
@flying-sheep I thought that by doing |
|
The checks shouldn't take any time. But you're right; you're also slicing the |
…tting multiple plots
|
@falexwolf I took the opportunity to add a change that I wanted with respect to the palette which is the ability to set a palette based on a matplotlib colormap. For example using or using I didn't want to modify the previous code that handles setting the palette to avoid breaking other code, but if we have some tests for other functions that use that functionality I could try to update the original methods. |
|
PS: The last image shows the new scatter compared to the old scatter. |
|
Argghh... I guess it's really also totally fine if things are no perfect squares anymore, really just change it if you feel it's easy... |
|
It is not much trouble to get something closer to a more square aspect, but the issue is whether the rcParams['figure.figsize'] is respected or not. To make room for the colormap on the right, the plot area is shrinked a bit but the figsize continues to be a square. In my view, the solutions are:
I will experiment a bit to see what is better. As for the panels_per_row, I think is better to use some standard naming. I will change that. |
|
I'd definitely say that So, having something that resembles a square a bit more, would be pretty, I think; but one should not get into writing messy custom code again... 😉 |
|
I noticed that matplotlib v. 3 is being installed in travis. This may be the reason why some tests not related to the changes are now failing. I am updating my matplotlib version to update de tests. |
|
I don't know what is happening with the new matplotlib but I had to increase the tolerance for the image comparison in order for the tests to pass. Locally I noticed small differences in the margins and axis labels. Also I noticed that running a single test is different than running several tests at once. This probably has to do with some internal matplotlib parameters that are modified. At least the tests are passing now. |
|
|
||
| sanitize_anndata(adata) | ||
| if color_map is not None: | ||
| print("instead of color_map use cmap") |
There was a problem hiding this comment.
We would usually do this using logg.warn but the convention of having size as a parameter is also present in several of matplotlib's and seaborn's functions. I regard a completely obscure parameter name such as s not as good coding style. These days, we want to be verbose. So, let's not discourage people from using clear parameter names.
There was a problem hiding this comment.
I am glad that you revised this as I wanted to ask you about those options but I forgot. I agree that s is quite misleading. Usually, matplotlib functions have a short and a long name, but in this case only the short is present. Let's remove the warning and use size as in seaborn, this needs to be added to the documentation as well. For color_map I don't know. Whatever is more consistent with other scanpy uses should be best.
|
@fidelram, really excited to try this out! I've got a couple questions about this PR:
|
|
|
Everything is in a very good shape, now. I'm merging this into master. Any further improvements can take off in a new branch from there. Thank you so much, @fidelram! |
|
|
@ivirshup For what you want we need to look into bokeh or plotly as they are optimized to render thousands of points quickly. I think that matplotlib is not going to be a solution here. Last week I played a bit with Dash and I found that is quite easy to set up an app to quickly explore gene expression. Maybe this is something that we can further develop. Currently, it uses matplotlib but I also tried it with plotly with decent results. Here is a very crude but functional demo using human lung airway data from Plasschaert et a. Nature. 2018. “A Single-Cell Atlas of the Airway Epithelium Reveals the CFTR-Rich Pulmonary Ionocyte.” https://doi.org/10.1038/s41586-018-0394-6.: https://demo-scexplorer.herokuapp.com/ |




I tried to collect in one file the code used for plotting functions that use matplotlib scatter like
sc.pl.tsne,sc.pl.pcaandsc.pl.umapand others.Also, I tried to annotate the code and improve the readability.
Currently, the code is on a separate file called
scatter.pyand not integrated into the API as this facilitates comparison with previous code.Besides readability the proposed code can:
matplotlib.pyplot.scatterlike vmax and vmin to adjust the color scale. When plotting multiple plots, this is useful to have a consistent range of values)See cells 15 and 15 in this example: https://gist.github.com/fidelram/8b43f786e7519bcfb7ffc0d5ccdbb0fe
If the admins would like to merge these changes I can replaced the previous functions.
An example on how to use the code:
Further examples here