question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

suggestion: set current ax to g.ax_joint at end of jointplot

See original GitHub issue

Tested with seaborn 0.11.1

jointplot (or JointGrid in general) leaves ax_marg_y as current axis. Some people try to use plt.xlim() or similar and are changing the marginal subplot instead of the main one. It could be nice to automatically set plt.sca(g.ax_joint) when finishing the jointplot.

Example code:

import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset('tips')
g = sns.jointplot(data=tips, x='total_bill', y='tip')
# plt.sca(g.ax_joint)
plt.axhline(tips['tip'].mean(), ls='--', c='r')
plt.axhspan(tips['tip'].quantile(.25), tips['tip'].quantile(.75), color='y', alpha=.3)
plt.show()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jhnclscommented, Apr 11, 2021

It probably would make sense to do the same for ax_heatmap of sns.clustermap. That way e.g. plt.xlabel('features') would affect the main subplot instead of the colorbar.

0reactions
mwaskomcommented, Mar 20, 2021

I think the easiest change would be to do it at the end of jointplot . People who are using JointGrid directly are probably less likely to get bitten by this. That said, calling plt.gca at the end of the JointGrid constructor is probably fine too; but I would worry about the unintended consequences of changing the direction of axis sharing so I’d be -1 on the second proposal.

By the way, a simple test of a non-seaborn function called with plot_marginals isn’t trivial.

A simple case would be:

g = sns.JointGrid(data=penguins, x="bill_length_mm", y="bill_depth_mm")
g.plot_marginals(plt.hist)

But yes, without an established API pattern for “which axis to draw the distribution on”, it’s harder to be generic in that function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In jointplot when using seaborn, how to set another legend in ...
1.I want to plot a joint distribution figure in 'hex' style with Seaborn, and I want to add a regression fitting using another...
Read more >
seaborn.jointplot — seaborn 0.12.1 documentation - PyData |
An object managing multiple subplots that correspond to joint and marginal axes for plotting a bivariate relationship or distribution. See also. JointGrid. Set...
Read more >
Understanding the jointplot vs jointgrid and the seaborn ...
Learn about the seaborn JointGrid in this Python seaborn tutorial video. I begin by explaining what is the joint grid and how it...
Read more >
Seaborn jointplot link x-axis to Matplotlib subplots
I think this is a case where setting up anycodings_jointplot the figure using matplotlib functions is anycodings_jointplot going to be better than working ......
Read more >
Joint Plot - Ajay Tech
The third plot is placed on the right margin of the bivariate graph with the orientation set to vertical and it shows the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found