2017-10-17 13 views
1

Seabornのジョイントプロット上の単一の点をハイライト表示しようとしていますが、ちょっと手をつけています。私はmatplotlibからポイントをプロットすることができます - それはちょうど同じグラフに表示されていません。私は間違って何をしていますか?ありがとう!Seabornグラフ:ジョイントプロットの単一のデータポイントを強調表示

import seaborn as sns 
import matplotlib.pyplot as plt 
%matplotlib inline 
import pandas as pd 

#make some sample data 
test_x = [i for i in range(10)] 
test_y = [j for j in range(10)] 

df = pd.DataFrame({'xs':test_x, 
        'ys':test_y}) 

#make Seaborn chart 
g = sns.jointplot(x="xs", y="ys", data = df) 


#sort the table to find the top y value 
df = df.sort_values('ys', ascending = False) 

#find coordinates of this point 
highlight_x = df.iloc[0,0] 
highlight_y = df.iloc[0,1] 

#this is wrong - I want it to be in the same chart 
plt.scatter(highlight_x, highlight_y, color = 'red') 

plt.show() 

Output from this code

答えて

1

plt.scatter現在の軸にプロットします。現在の軸は、明らかに中央の軸ではなく右側の軸です。したがって、プロットする軸を直接指定する方がよいでしょう。 JointGridgの中心軸がg.ax_jointを介して取得することができます。

g = sns.jointplot(...) 
# ... 
g.ax_joint.scatter(highlight_x, highlight_y, color = 'red') 
+0

すごい素敵な1 - おかげで...ので、近くにあった、まだ今のところ...それを感謝します! – user6142489

関連する問題