-
Notifications
You must be signed in to change notification settings - Fork 9
Plotting rework 1: use axes, use render_plot everywhere #166
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
Open
casblaauw
wants to merge
60
commits into
main
Choose a base branch
from
plotting_axes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…lor to region_predictions
Collaborator
Author
|
Ah shoot, comma'd arguments in docstrings (like sharex, sharey) currently repeat the same message for both in the docs. I was hoping they'd be shared on one line. I should probably split those out into separate arguments with separate explanations then. |
Collaborator
Author
|
This should be ready to review. Once uv learns how to install packages again, the tests should pass; they are passing for me locally, at least. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR reworks CREsted's plotting functions to be axis-focused according to a few core principles, inspired by scanpy and seaborn. Just in time for Christmas 😅
Core principles
Working with an
ax: Core plotting functions should accept an axis and some data and plot the data on that axis.sc.pl.umap(colors=['var1', 'var2']).Customizing the plotting function: The underlying plotting functions should be exposed through a
plot_kwsargument (like seaborn does for complicated functions with e.g.sns.lmplot(scatter_kws={}))pl.hist.distribution, without requiring all of them to be separate plotting function arguments (which can become overwhelming).Unified syntax: All plotting functions should use an identical syntax, aligning with each other and with matplotlib.
widthandheight, and is set on plot creation rather than post-hoc resizing.render_plotunless really not possible, and things like setting axis labels, titles, tick label rotations, etc, should as much as possible be handed off torender_plotby putting things inkwargsin the plotting functions. (This allows users to prevent any change to pre-existing properties by simply setting property=None in the plotting function)figsavearguments are all unified to usesave_pathinrender_plot(or manually if it's one of the few functions that doesn't use it).High-level summary:
render_plot(except a fewpl.patternsmodisco clustermaps)plot_kwsto add and customize the underlying plotting function's arguments.widthandheightto set dimensions, and multi-plot functions also takesharex/sharey.render_plotnow can also set ax-level labels and titles, set x/y lims, and add a grid.log_transformor not.Complete(ish) changelist:
bar:normalization_weights,region,region_predictions,prediction) now takeplot_kwsand all (exceptregion_predictions) also an axis.region_predictionsnow usesregionto plot its componentspredictionis cleaned up and made consistent with other functionsheatmapcorrelations_self,correlations_predictions) now take an axis and plot_kws.sns.heatmap(square=True)) by default, and default fig size was slightly changed to make it fit a square heatmap + a colorbar well.histhist.distributionnow takesplot_kwsand an optional axis.share_yis now renamed tosharey, as in matplotlib.locuslocus.locus_scoringnow takes an axis (if only plotting the locus scoring and not the extra bigwig track) and separate plot_kws for both the locus and bigwig plots. Previous custom arguments are now folded into the plot_kws or render_plot kwargs. Highlights can now also be customized with highlight_kws.locus.trackwas expanded from the beta function I implemented at some point.class_idx, instead of requiring the user to subset dimensions before passing in the data.patternscontribution_scores:highlight_kws._enhancer_design:enhancer_design_steps_predictionsnow takes an axis (if plotting one class) and plot_kws. Spelling mistake in the arguments fixed. Now always creates a square grid of plots if supplying a lot of classes, followinghist.distributions.enhancer_design_steps_contribution_scoresnow takes sharex/sharey and highlights can now be customized with highlight_kws._modisco_results: These plots are more convoluted/specific (and I very rarely use them), so I didn't touch them beyond the basics.render_plot. Clustermap functions now useg.savefig()as recommended by seaborn instead offig.savefig.clustermap_with_pwm_logospwm positioning logic was slightly adjusted, since they were all overlapping on my test run. Now they're all neatly aligned and separated in my tests at least.selected_instancesnow takes an axis if plotting a single index.cmapas an argument.scatterclass_densitycan now be customized more and has better defaults (figsize mostly square with or without colorbar, colorbar off by default, nicer labels)class_densitynow has properly colored and properly ranged colorbar.violin:violin.correlationsnow takes plot_kws and ax. Label adjusted if using log-transformed data.render_plot[x/y]_*arguments aligned with matplotlib and setting arguments (e.g.xlabel's fontsize is now set byxlabel_fontsizerather thanx_label_fontsize, also to preventsupx_label_fontsizewhich looks weird).[x/y]tick, sincex/ylabelrefers to the axis labels, not the axis tick labels.create_plotplt.subplotscalls, shorthand forif ax is not None; fig = ax.get_figure(); else; fig, ax = plt.subplots()Compatibility
I've endeavored to keep code as reverse compatible as possible.
show=False,render_plotdoes now return both a fig and ax(s), so code previously doingfig = crested.pl.func(show=False); axs = fig.axesor something similar will have to update tofig, axs = crested.pl.func(show=False)._modisco_results, I tested that all functions at least work with an old CREsted-based modisco run I had lying around, but haven't played with parameters a lot. Did not test the two TF expression-based plots (tf_expression_per_cell_type&clustermap_tf_motif), since I didn't have an elegans TF list available, so anyone testing those is appreciated.Future work
bar.region/bar.predictionautomatically also plotting multiple regions?rangetocontribution_scoresto plot on genomic coordinates (like withtrack())?track()with stuff from other functions, like center-zoom and highlights fromcontribution_scores-> see Expand pl.track.locus #161render_plotfor clustermaps?log_and_raise: currently looks bad in notebooks because it duplicates the error message, and makes errors uncatchable with try/except. Not sure what the advantages are.This is the first (and biggest) part of a plotting overhaul. The next parts will add some new plots, rework plot categorisation, and update all tutorials.