2017-10-18 10 views
1
import numpy as np 
import matplotlib as mpl 
import matplotlib.pyplot as plt 
import seaborn as sns 

d = ['d1','d2','d3','d4','d5','d6'] 
value = [111111, 222222, 333333, 444444, 555555, 666666] 

y_cumsum = np.cumsum(value) 
sns.barplot(d, value) 

sns.pointplot(d, y_cumsum) 
plt.show() 

私はバープロットとポイントプロットを使ってパレート図を作ろうとしています。しかし、私は右側のytickにパーセンテージを印刷することはできません。ちなみに、私がyticksをmanuplateすると、それ自体が重なっています。Sebororn right ytick

plt.yticks([1,2,3,4,5]) 

イメージのように重複します。

編集:私は、グラフィックの右側に1/4の割合(0,25%、50%、75%、100%)を設定したいと考えています。

+0

理由を私たちはその後、やらなければならないことは、いくつかのカスタムラベルを適切に、この第2の軸の制限を設定し、設定することです手動で設定したときに同じ場所にいるのは、スケールが70,000になったときに1,2,3,4,5が本質的に同じ場所にあるからです。パーセンテージ記号(右側の2番目の軸か、左側の各ytickの右側の軸)をどこにしたいのかを明確にするために編集できますか? –

+0

@Joel Ostblom私はちょうど右手に値リストの四分の一の合計を入れたいと思う。私は実際に新しい人物を作りませんでした。実際に私はまだこれを理解していない – yigitozmen

+0

0%、25%、50%、100%を意味する – yigitozmen

答えて

1

あなたが理解したところでは、あなたの体の右側にパーセンテージを表示したいと思います。これを行うには、twinx()を使用して2番目のy軸を作成します。

import matplotlib.pyplot as plt 
import numpy as np 
import seaborn as sns 

d = ['d1','d2','d3','d4','d5','d6'] 
value = [111111, 222222, 333333, 444444, 555555, 666666] 

fig, ax = plt.subplots() 
ax2 = ax.twinx() # create a second y axis 

y_cumsum = np.cumsum(value) 
sns.barplot(d, value, ax=ax) 

sns.pointplot(d, y_cumsum, ax=ax) 

y_max = y_cumsum.max() # maximum of the array 

# find the percentages of the max y values. 
# This will be where the "0%, 25%" labels will be placed 
ticks = [0, 0.25*y_max, 0.5*y_max, 0.75*y_max, y_max] 

ax2.set_ylim(ax.get_ylim()) # set second y axis to have the same limits as the first y axis 
ax2.set_yticks(ticks) 
ax2.set_yticklabels(["0%", "25%","50%","75%","100%"]) # set the labels 
ax2.grid("off") 

plt.show() 

これは、次の図生成します:あなたの目盛りが表示され

enter image description here