Draw a vertical line on seaborn jointplot

Viewed 619

I'm trying to draw a vertical line on a Seaborn Joint Plot and either get two plots, or an error stating ax is not iterable. The logic is as follows:

a4_dims = (12, 4)
fig, ax = plt.subplots(figsize=a4_dims)
ax.set_xlim(-.75, 1.25)
ax.set_ylim(-.75,1.25)
plt.axvline(0)
sns.jointplot(x='1_3Movement',y='1_2Movement',data=dfm,kind='kde', xlim=(-.75, 1.25), ylim=(-.75,1.25))

and this is what I get. enter image description here

1 Answers

Seaborn's jointplot creates its own figure and 3 axes. jointplot returns a JointGrid object. You can grab the individual axes via .ax_joint, .ax_marg_x and .ax_marg_y. To draw a line onto the contour plot part, use .ax_joint.

The jointplot is always a quadratic figure. The figsize can be set via height= (the width will be equal).

from matplotlib import pyplot as plt
import numpy as np
import seaborn as sns

kdeplot = sns.jointplot(x=np.random.normal(0.25, 0.5, 10), y=np.random.normal(0.25, 0.5, 10),
                          kind='kde', xlim=(-.75, 1.25), ylim=(-.75, 1.25), height=4)
# draw a vertical line on the joint plot, optionally also on the x margin plot
for ax in (kdeplot.ax_joint, kdeplot.ax_marg_x):
    ax.axvline(0, color='crimson', ls='--', lw=3)
plt.show()

resulting plot

Related