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

Re-use axis on a sns.jointplot() ? #294

Closed
sofiatti opened this issue Sep 17, 2014 · 4 comments
Closed

Re-use axis on a sns.jointplot() ? #294

sofiatti opened this issue Sep 17, 2014 · 4 comments
Labels

Comments

@sofiatti
Copy link

Hi,

I'm trying to plot something like this example. I'd like to add two other distributions to the same plot. But I don't think I can since jointplot is a figure-level function. It would be nice to able to, though. Keep up the great work with Seaborn!

Cheers,

Caroline

@mwaskom
Copy link
Owner

mwaskom commented Sep 17, 2014

Ah, you definitely can add stuff to plots made with figure-level functions, you just have to do so after calling them. In the case of jointplot, it returns an object of class JointGrid that exposes the three component axes at attributes called ax_joint, ax_marg_x, and ax_marg_y. So you can add you additional plots on those objects. Make sense?

@sofiatti
Copy link
Author

Right. I can add a plot, but it doesn't generate all the bells and whistles that jointplot does. I want to get something like the figure 3 in this paper. I was going to worry about the contour aspect of the plot afterwards.

Thanks for the quick reply! I closed this by mistake. I'm sorry.

@sofiatti sofiatti reopened this Sep 18, 2014
@mwaskom
Copy link
Owner

mwaskom commented Sep 18, 2014

I think in your case I'd do something like this using the tips dataset as an example:

tips = sns.load_dataset("tips")
g = sns.JointGrid("total_bill", "tip", tips)
for day, day_tips in tips.groupby("day"):
    sns.kdeplot(day_tips["total_bill"], ax=g.ax_marg_x, legend=False)
    sns.kdeplot(day_tips["tip"], ax=g.ax_marg_y, vertical=True, legend=False)
    g.ax_joint.plot(day_tips["total_bill"], day_tips["tip"], "o", ms=5)

Requires a little more work on your end than just using jointplot, but a lot less than building from scratch with pure matplotlib.

@sofiatti
Copy link
Author

Perfect! It works great!!! I'll send you an e-mail with my plot. Thank you so much for the quick responses! I'm at a conference with Fernando Perez. He said he'll see you soon and I asked him to thank you in person. ;)

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

No branches or pull requests

2 participants