python - How to plot multiple Seaborn Jointplot in Subplot -


i'm having problem placing seaborn jointplot inside multicolumn subplot.

import pandas pd import seaborn sns  df = pd.dataframe({'c1': {'a': 1,'b': 15,'c': 9,'d': 7,'e': 2,'f': 2,'g': 6,'h': 5,'k': 5,'l': 8},           'c2': {'a': 6,'b': 18,'c': 13,'d': 8,'e': 6,'f': 6,'g': 8,'h': 9,'k': 13,'l': 15}})  fig = plt.figure();    ax1 = fig.add_subplot(121);   ax2 = fig.add_subplot(122);  sns.jointplot("c1", "c2", data=df, kind='reg', ax=ax1) sns.jointplot("c1", "c2", data=df, kind='kde', ax=ax2) 

notice how portion of jointplot placed inside subplot , rest left inside 2 plot frames. i'd want have both distributions inserted inside subplots.

can this?

it can not done without hacking. jointplot calls jointgrid method, in turn creates new figure object every time called.

therefore, hack make 2 jointplots (jg1 jg2), make new figure, migrate axes objects jg1 jg2 new figure created.

finally, adjust sizes , positions of subplots in new figure created.

jg1 = sns.jointplot("c1", "c2", data=df, kind='reg') jg2 = sns.jointplot("c1", "c2", data=df, kind='kde')  #subplots migration f = plt.figure() j in [jg1, jg2]:     in j.fig.axes:         f._axstack.add(f._make_key(a), a)  #subplots size adjustment f.axes[0].set_position([0.05, 0.05, 0.4,  0.4]) f.axes[1].set_position([0.05, 0.45, 0.4,  0.05]) f.axes[2].set_position([0.45, 0.05, 0.05, 0.4]) f.axes[3].set_position([0.55, 0.05, 0.4,  0.4]) f.axes[4].set_position([0.55, 0.45, 0.4,  0.05]) f.axes[5].set_position([0.95, 0.05, 0.05, 0.4]) 

it hack because using _axstack , _add_key private methods, might , might not stay same in matplotlib future versions.

enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -