【问题标题】:seaborn mixing of plotsseaborn 混合地块
【发布时间】:2021-07-10 22:46:58
【问题描述】:

我在 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)

我想创建两个地块。但这些情节重叠。怎样才能把最后两行的图形分开?

【问题讨论】:

  • 那么,有什么问题?
  • 绘制在彼此之上。我怎样才能分开
  • 请在您的帖子中描述您的问题(不是 cmets)。您可以edit 并在那里添加信息。说明您想要分离哪些数据以及如何分离。

标签: python pandas seaborn


【解决方案1】:

您需要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

【讨论】:

    猜你喜欢
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 2019-12-23
    • 1970-01-01
    • 2021-09-30
    • 2020-08-16
    相关资源
    最近更新 更多