Skip to content
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

Support for passing most plotting functions to seaborn grids #306

Closed
remrama opened this issue Oct 10, 2022 · 2 comments
Closed

Support for passing most plotting functions to seaborn grids #306

remrama opened this issue Oct 10, 2022 · 2 comments
Assignees
Labels
feature request 🚧 New feature or request

Comments

@remrama
Copy link
Contributor

remrama commented Oct 10, 2022

Hi @raphaelvallat , I'm wondering how tied you are to generating figures explicitly in most of pingouin's plotting functions (e.g., plot_blandaltman). Currently, most of these plotting functions generate a figure explicitly when the ax parameter is not provided, something like:

if ax is None:
    fig, ax = plt.subplots(1, 1, figsize=figsize, dpi=dpi)

I think it might be better or more flexible to generate a figure with default size the way seaborn does:

if ax is None:
    ax = plt.gca()

Seems trivial, but if it's set up this way, then the function can be used to "map" plots onto seaborn grids (e.g., this demo). It would be great if pingouin's plotting functions could be applied to this popular seaborn feature. Other very minor changes would also need to happen, namely taking a color parameter (see here).

Other reasons to favor this change:

  • As far as I can tell, you don't lose anything except the ability to specify figure details. BUT that's where the ax parameter gets its use; if someone wants a figure a specific size, they open up the figure themselves (specifiying size, dpi, etc.) and then pass the ax in. Ultimately this has more complete flexibility and suggests the user build their own figure if they are concerned about aesthetic details.
  • Currently, when ax is used, figsize (and and sometimes dpi) is ignored. This is slightly confusing so this avoids that as well.

This would of course not apply to any figures that need to build their own, like anything using seaborn facetgrids. At a glance, I think this change could apply to the following functions:

  • plot_blandaltman
  • plot_paired
  • plot_circmean
  • qqplot (also dropping the automatic Title here would help compatibility with seaborn)

Note there is a 3rd option where you could have both. You could check if a figure already exists, and then if not build one with the arguments passed to the pingouin plotting function. I don't favor this much, but just mentioning it.

If you're into this I'd be happy to make the pull request.

@remrama
Copy link
Contributor Author

remrama commented Oct 10, 2022

Just now realizing something like this (from FacetGrid docs) could probably be reworked as a clunky work-around to my specific concern:

import matplotlib.pyplot as plt
def annotate(data, **kws):
    n = len(data)
    ax = plt.gca()
    ax.text(.1, .6, f"N = {n}", transform=ax.transAxes)

g = sns.FacetGrid(tips, col="time")
g.map_dataframe(sns.scatterplot, x="total_bill", y="tip")
g.map_dataframe(annotate)

Basically a wrapper for pingouin plotting functions could use plt.gca() and pass that as ax to pingouin.

Putting this here for completeness but I still think the more general solution is better with some additional side benefits.

@raphaelvallat raphaelvallat added the feature request 🚧 New feature or request label Oct 10, 2022
@raphaelvallat
Copy link
Owner

Hi @remrama,

Thanks for the detailed issue. I don't see any reasons why not to implement your proposed solution, and I agree that it may improve flexibility and at the same time simplify Pingouin's API. Please feel free to work on a PR 👍

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

No branches or pull requests

2 participants