1

I have 2 diagrams and they superimposed on one another How can i display them side by side?

sns.histplot(data=dataset.loc[dataset['Survived'] == 0, 'Age'], color='green') \      
 .set(xticks=range(0, 81, 5), title='Survived= 0');

 sns.histplot(data=dataset.loc[dataset['Survived'] == 1, 'Age'], color='purple') \
  .set(xticks=range(0, 81, 5), title='Survived= 1');
Antonio
  • 11
  • 1
  • `sns.histplot(data=dataset, x='Age', hue='Survived', palette['green','purple'], multiple='dodge')` – JohanC Mar 31 '22 at 22:01

1 Answers1

0

You can instantiate a figure object with two columns and pass the individual columns as ax keyword-arguments to sns.histplot, like so:

dataset = sns.load_dataset('titanic')

fig, ax = plt.subplots(ncols=2)

sns.histplot(data=dataset.loc[dataset['survived'] == 0, 'age'], color='green', ax=ax[0]).set(xticks=range(0, 81, 5), title='Survived= 0');

sns.histplot(data=dataset.loc[dataset['survived'] == 1, 'age'], color='purple', ax=ax[1]).set(xticks=range(0, 81, 5), title='Survived= 1');
warped
  • 8,947
  • 3
  • 22
  • 49