How to plot these graphics side by side?

Viewed 38

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');
1 Answers

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');
Related