ACCLAB / DABEST-python

Data Analysis with Bootstrapped ESTimation
https://acclab.github.io/DABEST-python/
Apache License 2.0
341 stars 47 forks source link

Specify axes for plots #66

Closed anekimken closed 4 years ago

anekimken commented 5 years ago

In some figures, the estimation plot will only be one panel of the figure. It would be useful to have the ability to specify which axes to use to draw the plot, similar to the ax option in seaborn. In this case, two axes will be required for the two elements of the plot.

In principle, one could save the figure as an image and put together a figure in Illustrator or similar, but it would be nice to generate the whole figure in code.

josesho commented 5 years ago

Hi @anekimken,

This is a great suggestion. It's something I've thought about before.

If I can frame it from a toolkit/intended purpose perspective: seaborn (and matplotlib) are positioned as omnibus all-purpose plotting libraries. Hence they have such features as you allude to: the ability to plot different Axes objects in the same Figure.

For the case of estimation graphics and dabest, two Axes objects are required: one to plot the rawdata as swarmplots, and one to chart the effect size and the bootstrap distribution. The easiest way to do this was to create a Figure object with two Axes (appropriately sized and aligned), and then returning this to the user.

Arbitrary specification of which Axes to plot on would work for Cumming plots, but I'm not so sure they might work for Gardner-Altman plots; the latter requires horizontal alignment of the 2 axes. (If you plot the effect size in a non-aligned axes, it more or less defeats the purpose of the Gardner-Altman design?)

I suppose with some work the API could be tweaked to something like:

f, axx = plt.subplots(nrows=2, ncols=2)

my_data = dabest.load(df, idx=("control", "test"))

my_data.mean_diff.plot(swarm_ax=axx[0], effsize_ax=axx[1]);

Happy to accept a PR if you have a prototype! Currently I'm not sure it is a development priority.

Thanks for listening!

anekimken commented 5 years ago

Hi @josesho, I'll take a look at it.

What do you think about using an inset axes instead of two axes? Most of the demos only use colorbars, but it looks possible to make a plot instead. The api for accessing the two axes may need to change a bit, but probably not much.

josesho commented 5 years ago

Sounds possible; happy to see what you come up with! Let's review when you have a PR.

josesho commented 5 years ago

Thanks for PR #73; which very nicely addresses this. I'm currently cleaning it up and updating docstrings. Thanks!