I'm doing some EDA on a dataset I have using seaborn
primarily. However, I'd like to plot these graphs in a single kernel. I think I'm meant to use matplotlib
to achieve this. I've done 3 separate sns.countplot
graphs, but I'm trying to show them in one single kernel/output.
I've tried using the following code but I'm still not entirely sure how it works:
fig, axes = plt.subplots(1, 3, figsize=(16,8))
ax = sns.countplot(y = 'loan_status', data = df, order = df['loan_status'].value_counts().iloc[:6].index)
ax = sns.countplot(y = 'loan_status', data = df, order = df['loan_status'].value_counts().iloc[2:9].index)
ax = sns.distplot(df['loan_amnt'], bins=50)
Do you mean something like this?
Here is a simple example:
import numpy as np
import matplotlib.pyplot as plt
# Some random data to plot
M = np.random.rand(3,100,100)
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(16,8))
for i, ax in enumerate(axes.flatten()):
ax.imshow(M[i])
# OR
# axes[0].imshow(M[0])
# axes[1].imshow(M[1])
# axes[2].imshow(M[2])
plt.show()
Try this.
fig, [ax1, ax2, ax3] = plt.subplots(1, 3, figsize=(16,8))
ax1 = sns.countplot(y = 'loan_status', data = df, order = df['loan_status'].value_counts().iloc[:6].index)
ax2 = sns.countplot(y = 'loan_status', data = df, order = df['loan_status'].value_counts().iloc[2:9].index)
ax3 = sns.distplot(df['loan_amnt'], bins=50)
fig.tight_layout()
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.