seaborn情节混合

uinbv5nw  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(364)

在spyder中创建此情节时遇到问题:

import seaborn as sns
import pandas as pd
from pandas.api.types import CategoricalDtype
diamonds= sns.load_dataset("diamonds")
df=diamonds.copy()
cut_Kategoriler=["Fair","Good","Very Good","Premium","Ideal"]
df.cut=df.cut.astype(CategoricalDtype(categories = cut_Kategoriler,ordered=True))
print(df.head())
sns.catplot(x="cut",y="price",data=df)
sns.barplot(x="cut",y="price",hue="color",data=df)

我想创造两个情节。但这些阴谋已经越界了。如何将最后两行中的图形分开?

hjzp0vay

hjzp0vay1#

你需要 import matplotlib.pyplot as plt 然后加上 plt.show() 在两个情节中的每一个之后。
修改后的代码添加如下:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt # Import Matplotlib
from pandas.api.types import CategoricalDtype

diamonds = sns.load_dataset("diamonds")

df=diamonds.copy()
cut_Kategoriler=["Fair","Good","Very Good","Premium","Ideal"]

df.cut=df.cut.astype(CategoricalDtype(categories = cut_Kategoriler,ordered=True))

print(df.head())

sns.catplot(x="cut",y="price",data=df)
plt.show() # Display the first plot
sns.barplot(x="cut",y="price",hue="color",data=df)
plt.show() # Display the second plot

相关问题