When attempting to plot two distributions side-by-side using sns.displot, users may encounter empty subplots followed by the expected displot on subsequent lines. This behavior is due to the deprecation of sns.distplot in favor of the more flexible displot and histplot functions.
seaborn.displot is a figure-level function that lacks an ax parameter, while sns.histplot is an axes-level function that does have an ax parameter. This means that displot cannot be used with matplotlib.pyplot.subplots, while histplot can be used to visualize two plots on the same line.
To resolve the issue, you should use sns.histplot for your desired purpose. Here's an example:
<code class="python">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>
If you want to plot distributions from multiple dataframes, you can:
The above is the detailed content of Why Are My Seaborn `displot` Subplots Empty?. For more information, please follow other related articles on the PHP Chinese website!