2021-01-19に更新

Ridgeline plotの描き方

複数の分布をグループorカテゴリ別に重ね合わせて表示する図(Ridgeline plots)の書き方.Joyplotとも言う?

from scipy.stats import gaussian_kde
import matplotlib.pyplot as plt


plt.figure(figsize=(4, 6), dpi=150)
def ridgeline(data,overlap=0.5,fill=True,labels=None,n_points=150):
    xx=np.linspace(np.min(np.concatenate(data)),np.max(np.concatenate(data)),n_points)
    curves=[]
    ys=[]
    for i,d in enumerate(data):
        pdf=gaussian_kde(d)
        y=i*(1.0-overlap)
        curve=pdf(xx)
        if fill:
            plt.fill_between(xx,np.ones(n_points)*y,curve+y,zorder=len(data)-i+1,alpha=0.1,color=fill)
        plt.plot(xx,curve+y,c='k',zorder=len(data)-i+1)
        plt.xlim(-1,1)
        #plt.ylim(10,50)
    if labels:
        plt.yticks(ys,labels)
data=(FFT[index,19+10:19+51]-GA[index,19+10:19+51]).T
print(np.shape(data))
ridgeline(data,overlap=0,fill='blue')

image

ツイッターでシェア
みんなに共有、忘れないようにメモ

kawai_mizugorou

社会人2年目.自分用のメモとして使ってます.

Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。

また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!

有料記事を販売できるようになりました!

こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?

コメント