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

JointGrid could have axhline/axvline analogues that would plot on joint and marginal axes #2249

Closed
mwaskom opened this issue Sep 5, 2020 · 3 comments · Fixed by #2620
Closed

Comments

@mwaskom
Copy link
Owner

mwaskom commented Sep 5, 2020

Would need to thing about the right name, but probably a good idea.

@stefmolin
Copy link
Contributor

stefmolin commented Jun 26, 2021

Do you mean something like this?

image

I added a plot_refline() method to prototype this on my fork:

JointGrid.plot_refline(self, *, value, orient, joint=True, marginal=True, **kwargs)

It would be called like this:

import seaborn as sns

penguins = sns.load_dataset('penguins')
g = sns.jointplot(data=penguins, x='bill_length_mm', y='bill_depth_mm')

# by default plot on both the marginal and joint axes
g.plot_refline(value=16, orient='h', linestyle='dashed', color='gray')

# only on joint
g.plot_refline(value=45, orient='v', marginal=False, linestyle='dotted', color='red')

# only on marginal
g.plot_refline(value=55, orient='v', joint=False, linestyle='dashed', color='blue')

I'm happy to make the PR if this is indeed what you meant.

@mwaskom
Copy link
Owner Author

mwaskom commented Jun 29, 2021

Yes, basically. But I think I would prefer the following API:

JointGrid.refline(self, x: float | None = None, y: float | None = None, **line_kws)

I'm ambivalent about having joint and marginal parameters as booleans defaulting to True. It feels like one could just call the underlying matplotlib function if you only want a line on one subplot.

@stefmolin
Copy link
Contributor

Sure, I'll update the API to what you mentioned.

With regards to the joint and marginal parameters, I agree that matplotlib could just be used to plot a single line. However, the caller needs to know how to access the individual plots in the JointGrid. I just took a quick look at the seaborn docs, and while they do state that, for example ax_marg_x is the way to access one of the marginal plots, you have to know what you are looking for to find it (since there is no attributes section in the docs and the example is halfway through the page). So perhaps having these parameters does indeed add value? Also, the JointGrid class does have a method for saving the plot, which can also be done via matplotlib directly – I think it comes down to defining where the line between seaborn and matplotlib is/should be, and I'll defer to you on that one 😃

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

Successfully merging a pull request may close this issue.

2 participants