2016-07-06 15 views
2

私はこのようになりますカテゴリーデータを含むパンダデータフレームを持っている:Seabornのstripplotとエラーバー

 cat  DM3_r DM3_r_err 
133 stuff 9.908949 0.442363 
1347 foo 1.156828 0.130174 
132 bar 0.818709 0.593341 
1350 stack 0.798348 0.089866 
977 over 0.724274 0.462868 
1054 flow 0.546665 0.538208 
1228 run 0.425070 0.571659 
1009 run 0.316554 0.259385 
1109 yadG 0.304657 0.401482 

私は、データを視覚化するためにseabornのstripplotを使用しています:"cat"の異なるグループのため

seaborn.stripplot(df.DM3_r, df.cat, size=7, orient="h", 
       palette="Reds_r", edgecolor="gray", ax=ax.flat[i], linewidth=.5) 

をこの場合。これは正常に動作します。しかし、エラー"DM3_r_err"を追加したいと思います。

私はすでにerrorbarからmatplotlibにエラーバープロットを追加しましたが、海底チャートのポイントの位置を抽出できませんでした。これは、私がサブプロットを使用していることが原因です。

シーボーンを使用する直接の方法はありますか?

これはstripplotがどのように見える(左)と右側に私が目指すものです方法です: enter image description here

答えて

2

Pandas.DataFrameからデータを選択するためのよりスマートな方法があるかもしれませんが、このようなものは動作します:

import pandas as pd 
import matplotlib.pylab as pl 
import seaborn 
import numpy as np 

pl.close('all') 

data = [['hsdM', 3.908949, 1.442363], 
     ['lolD', 1.156828, 0.456434], 
     ['lolD', 3.156828, 0.230174], 
     ['acrB', 0.546665, 0.538208], 
     ['msbA', 0.425070, 0.571659], 
     ['msbA', 2.425070, 1.571659], 
     ['emrA', 0.316554, 1.259385], 
     ['yadG', 0.304657, 0.401482]] 

df = pd.DataFrame(data, columns=['gene','DM3_r','DM3_r_err']) 

pl.figure() 
ax = pl.subplot(111) 

# Everywhere below you would have to replace `ax` with your `ax.flat[i]` 
sp = seaborn.stripplot(df.DM3_r, df.gene, size=7, orient="h", 
        palette="Reds_r", edgecolor="gray", ax=ax, linewidth=.5) 

for y,ylabel in zip(ax.get_yticks(), ax.get_yticklabels()): 
    f = df['gene'] == ylabel.get_text() 
    ax.errorbar(df.DM3_r[f].values, np.ones_like(df.DM3_r[f].values)*y, xerr=df.DM3_r_err[f].values, ls='none') 

enter image description here

+1

あなた@Bartをありがとうございます。私は実際にy軸のティック位置を使って同じものを考え出しました。 – Fourier

関連する問題