2017-05-30 11 views
0

バイオリンプロットの平均の外観を変更したいと思います。私はmatplotlibを使用しています。私は、次のコードでの手段の色を変更できます。バイオリンプロットの平均インジケータを円に変更

import matplotlib.pyplot as plt 

fig,(axes1,axes2,axes3) = plt.subplots(nrows=3,ncols=1,figsize=(10,20)) 

r=axes2.violinplot(D,showmeans=True,showmedians=True) 
r['cmeans'].set_color('red') 

しかし、今、私は「小さな円」に平均値(中央値のような現在の行)の外観を変更したいです。 誰かがこれを手伝ってくれますか?

+0

おそらく、あなたの現在のプロットが見てどのように投稿することができます。また、あなたの問題が何であるかを明確に理解するために、いくつかの詳細を追加してください。 –

答えて

0

平均線の座標を取得し、それらの座標に散布図をプロットすることが考えられます。座標を取得

    でき
  • いずれか

  • または入力データから平均値をreacalculatingすることにより、平均線パスを介してループすることによって行われます。

    #alternatively get the means from the data 
    y = data.mean(axis=0) 
    x = np.arange(1,len(y)+1) 
    xy=np.c_[x,y] 
    

完全なコード:

import matplotlib.pyplot as plt 
import numpy as np; np.random.seed(1) 

data = np.random.normal(size=(50, 2)) 

fig,ax = plt.subplots() 

r=ax.violinplot(data,showmeans=True) 

# loop over the paths of the mean lines 
xy = [[l.vertices[:,0].mean(),l.vertices[0,1]] for l in r['cmeans'].get_paths()] 
xy = np.array(xy) 
##alternatively get the means from the data 
#y = data.mean(axis=0) 
#x = np.arange(1,len(y)+1) 
#xy=np.c_[x,y] 

ax.scatter(xy[:,0], xy[:,1],s=121, c="crimson", marker="o", zorder=3) 

# make lines invisible 
r['cmeans'].set_visible(False) 

plt.show() 

enter image description here

+0

ありがとう!最初の方法は完全に機能します! :) – Leo