如何叠加 seaborn 的两个密度图?

问题描述 投票:0回答:1

我想绘制两个不同的密度图,一个在同一个图表上,同一个轴上。

这是我试过的代码:

# setting the dimensions of the plot
fig, ax = plt.subplots(figsize=(16, 9))
 
# drawing the plot
sns.displot(np.random.randint(25,size=500), kind = "kde")
sns.displot(np.random.randint(25,size=500), kind = "kde")

我只得到最后一次抽奖,但没有达到我想要的大小。

python seaborn overlay
1个回答
0
投票
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

fig = sns.kdeplot(np.random.randint(25,size=500), shade=True, color="r")
fig = sns.kdeplot(np.random.randint(25,size=500), shade=True, color="b")
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.