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.

Subplots and JointGrid

See original GitHub issue

Say I create a figure that will hold multiple plots, one of which I want to be a JointGrid

f = plt.figure(figsize=(12,6))
gs = gridspec.GridSpec(4,1 , height_ratios=[1.5,1.5,1.5, 1.5])
subplots = list(gs)
first_axis = f.add_subplot(subplots[0])

I would like to create a JointGrid plot on this axis. Is there any way to do that?

JointGrid does not seem to accept an ax parameter, I guess because it creates several axes (multiple of them, presumably), i.e. this doesn’t work:

sns.JointGrid(xcol, ycol, df, size=12, ax=first_axis)

How can I use sns.JointGrid with subplot?

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
ImportanceOfBeingErnestcommented, Dec 3, 2017

I wrote a small class in this Stackoverflow anser that would allow to transfer a plot from one of the figure type seaborn graphs to a position of a gridspec in a different matplotlib figure. There are some minor issues still, so such solution needs a bit tweaking, but is in principle usable.

The output might then look something like this: image

2reactions
bendichtercommented, Apr 13, 2017

I have implemented this!

fig = plt.figure(figsize=(16,8))
gs = gridspec.GridSpec(1,2, wspace=.2)

fig.add_subplot(gs[0])
iris = sns.load_dataset("iris")
g = sns.PairGrid(iris, subplot_spec=gs[1])
g = g.map(plt.scatter)

download 63

sns.pairplot(iris, grid_kws={'subplot_spec':gs[1]}) also works.

I also implemented it for JointGrid:

fig = plt.figure(figsize=(8,4))
gs = gridspec.GridSpec(1,2, wspace=.2)

fig.add_subplot(gs[0])
g = sns.JointGrid(x="total_bill", y="tip", data=tips, size=5, ratio=2, 
                  subplot_spec=gs[1])
g = g.plot_joint(sns.kdeplot, cmap="Reds_d")
g = g.plot_marginals(sns.kdeplot, color="r", shade=True)

download 64

(similar results for g = sns.jointplot(x="total_bill", y="tip", kind='kde',data=tips, size=5, ratio=2, subplot_spec=gs[1]))

The JointPlot/jointplot implementation was pretty straightforward, however, PairGrid/pairplot depends on a change to matplotlib that is in the master branch but has not yet been released. The implementation of plt.subplots() was recently moved to fig.subplots(). That change allowed me to implement this without a giant overhaul to seaborn, because it allowed me to call subplots and use the sharex and sharey optional arguments on a pre-existing figure. To do it with the current release, one would have to implement sharex and sharey themselves. Then we’d probably want to change it to this implementation once the mpl update occurs anyway so I feel like that would be a waste.

I’m new to contributing, so I don’t know what the standard protocol is for features that rely on not-yet-released dependencies. Please advise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to plot multiple Seaborn Jointplot in Subplot
jointplot calls JointGrid method, which in turn creates a new figure object every time it is called. Therefore, the hack is to make...
Read more >
seaborn.JointGrid — seaborn 0.12.1 documentation - PyData |
Set up the grid of subplots and store data internally for easy plotting. Parameters: data pandas.DataFrame , numpy.ndarray , mapping, or ...
Read more >
Understanding the jointplot vs jointgrid and the seaborn ...
Learn about the seaborn JointGrid in this Python seaborn tutorial video. ... or for the individual subplots or with the JointGrid methods.
Read more >
How to plot a non-square Seaborn jointplot or JointGrid ...
Steps. Set the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Create...
Read more >
JointGrid - Ajay Tech
Few of the functions defined in pyplot are used at this level such as figure(), subplot() in order to create figure and axes...
Read more >

github_iconTop Related Medium Post

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