Home > Article > Backend Development > Why Won\'t Seaborn.displot() Create Side-by-Side Histograms?
When using seaborn.displot() to create two side-by-side histograms, you may encounter an unexpected outcome where the plots are rendered separately on different lines. This behavior differs from other seaborn functions like violinplot() that produce the expected side-by-side plots.
The reason for this discrepancy lies in the deprecation of seaborn.distplot in version 0.11. It has been replaced by:
To resolve the issue and achieve the desired side-by-side histograms, replace displot() with histplot(). This function supports the ax parameter, allowing you to specify the axes on which the plots will be rendered.
<code class="python">import seaborn as sns import matplotlib.pyplot as plt fig, (ax1, ax2) = plt.subplots(1, 2) sns.histplot(x=X_train['Age'], hue=y_train, ax=ax1) sns.histplot(x=X_train['Fare'], hue=y_train, ax=ax2)</code>
When working with multiple dataframes, you can combine them using pd.concat and add a new 'source' column to identify the data sources. This column can then be used for row=, col=, or hue= arguments.
The above is the detailed content of Why Won\'t Seaborn.displot() Create Side-by-Side Histograms?. For more information, please follow other related articles on the PHP Chinese website!