你如何在 python 中分离 seaborn 地块?
How do you seperate seaborn plots in python?
现在我有四个不同的 regplots 我想展示,但是,它们似乎都组合在 1 个图下。请帮我把它们分成 4 个不同的地块。
sns.regplot(x = df["Rank"].head(100), y = df["Assets"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Market Value"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Sales"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Profit"].head(100))
尝试以下操作:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
data = {'Rank': [3, 2, 1, 0], 'Assets': [1, 2, 3, 4], 'Market Value': [5, 6, 7, 8], 'Sales': [9, 10, 11, 12], 'Profit': [13, 14, 15, 16]}
df = pd.DataFrame.from_dict(data)
fig, axs = plt.subplots(ncols=4, figsize=(16,3))
sns.regplot(x = df["Rank"].head(4), y = df["Assets"].head(4), ax=axs[0])
sns.regplot(x = df["Rank"].head(4), y = df["Market Value"].head(4), ax=axs[1])
sns.regplot(x = df["Rank"].head(4), y = df["Sales"].head(4), ax=axs[2])
sns.regplot(x = df["Rank"].head(4), y = df["Profit"].head(4), ax=axs[3])
您还可以添加
plt.show()
在每行之后。
现在我有四个不同的 regplots 我想展示,但是,它们似乎都组合在 1 个图下。请帮我把它们分成 4 个不同的地块。
sns.regplot(x = df["Rank"].head(100), y = df["Assets"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Market Value"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Sales"].head(100))
sns.regplot(x = df["Rank"].head(100), y = df["Profit"].head(100))
尝试以下操作:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
data = {'Rank': [3, 2, 1, 0], 'Assets': [1, 2, 3, 4], 'Market Value': [5, 6, 7, 8], 'Sales': [9, 10, 11, 12], 'Profit': [13, 14, 15, 16]}
df = pd.DataFrame.from_dict(data)
fig, axs = plt.subplots(ncols=4, figsize=(16,3))
sns.regplot(x = df["Rank"].head(4), y = df["Assets"].head(4), ax=axs[0])
sns.regplot(x = df["Rank"].head(4), y = df["Market Value"].head(4), ax=axs[1])
sns.regplot(x = df["Rank"].head(4), y = df["Sales"].head(4), ax=axs[2])
sns.regplot(x = df["Rank"].head(4), y = df["Profit"].head(4), ax=axs[3])
您还可以添加
plt.show()
在每行之后。