python - Prevent Overlapping in FacetGrid using col, row, and hue -


i have plot looks fine

import seaborn sns tips = sns.load_dataset('tips')  sns.violinplot('day', 'total_bill', data=tips, hue='sex') 

enter image description here

however, when want create facet using facetgrid object, violins, in example, plotted on top of eachother. how prevent tha happening male , female plotted next each other?

facet = sns.facetgrid(tips, col='time', row='smoker', hue='sex',                  hue_kws={'male':'blue', 'female':'green'}). facet.map(sns.violinplot, 'day', 'total_bill') 

enter image description here

seems solution is:

import seaborn sns facet = sns.facetgrid(tips, col="time", row='smoker') facet.map(sns.violinplot, 'day', 'total_bill', "sex") 

enter image description here

passing sex map call seems wanted. name of parameter sex assigned to? it's not hue. know being passed here?

the other way barebones matplotlib.pyplot level

import matplotlib.pyplot plt import seaborn sns  facet_fig = plt.figure() ax1 = facet_fig.add_subplot(2, 2, 1) ax2 = facet_fig.add_subplot(2, 2, 2) ax3 = facet_fig.add_subplot(2, 2, 3) ax4 = facet_fig.add_subplot(2, 2, 4)      sns.violinplot(x='day', y='total_bill', hue='sex', ax=ax1,                data=tips[(tips.smoker=='yes') & (tips.time == 'lunch')]) sns.violinplot(x='day', y='total_bill', hue='sex', ax=ax2,                data=tips[(tips.smoker=='yes') & (tips.time == 'dinner')]) sns.violinplot(x='day', y='total_bill', hue='sex', ax=ax3,                data=tips[(tips.smoker=='no') & (tips.time == 'lunch')]) sns.violinplot(x='day', y='total_bill', hue='sex', ax=ax4,                data=tips[(tips.smoker=='no') & (tips.time == 'dinner')]) 

enter image description here


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -