I have two pandas
dataframes I would like to plot in the same seaborn jointplot. It looks something like this (commands are don in an IPython shell; ipyth
A better solution, in my opinion, is to use the axes handles for the joint and marginal distributions that sns.joinplot
returns. Using those (the names are ax_joint
, ax_marg_x
and ax_marg_y
) is also possible to draw on the marginal distributions plots.
import seaborn as sns
import numpy as np
data1 = np.random.randn(100)
data2 = np.random.randn(100)
data3 = np.random.randn(100)
data4 = np.random.randn(100)
df1 = pd.DataFrame({'col1': data1, 'col2':data2})
df2 = pd.DataFrame({'col1': data3, 'col2':data4})
axs = sns.jointplot('col1', 'col2', data=df1)
axs.ax_joint.scatter('col1', 'col2', data=df2, c='r', marker='x')
# drawing pdf instead of histograms on the marginal axes
axs.ax_marg_x.cla()
axs.ax_marg_y.cla()
sns.distplot(df1.col1, ax=axs.ax_marg_x)
sns.distplot(df1.col2, ax=axs.ax_marg_y, vertical=True)