2017-07-20 89 views
0

我有兩個密度圖,一個在另一個之上。如何用兩種不同顏色填充曲線下方的區域,並添加一些透明度,以使重疊區域明顯。用python填充顏色密度圖

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
import sys 
import seaborn as sns 

x=[1,1,1,1,1,1,1,0,0,0,0,0,0,0] 
y=[1,1,1,0,2,0,0,0,1,1,0,1,0,1] 
sns.distplot(x, hist=False,color="green") 
sns.distplot(y, hist=False,color="blue") 

enter image description here

回答

3

你試過sns.kdeplot(x, hist=False, color="green", shade=True)? 顯然他們創造了相同的曲線。

從我可以告訴它是默認透明,這應該滿足您的要求。

import matplotlib.pyplot as plt 
import seaborn as sns 

x=[1,1,1,1,1,1,1,0,0,0,0,0,0,0] 
y=[1,1,1,0,2,0,0,0,1,1,0,1,0,1] 
sns.kdeplot(x, color="green", shade=True) 
sns.kdeplot(y, color="blue", shade=True) 
plt.show() 

seaborn documentation

這裏是結果圖:

Graph result

+1

存在distplot沒有樹蔭參數 –

+0

「_We可以看到,如果我們使用kdeplot()函數seaborn,我們得到相同的曲線,這個函數被distplot()使用,但它提供了一個更直接的接口,當你只需要密度估計時,可以更容易地訪問其他選項:_「 - 從上面的Seaborn文檔鏈接。 基本上,使用'kdeplot()'看看你是否得到相同的曲線。 – Eqomatic

+0

你能分享一下代碼嗎? –