2017-07-27 1 views

答えて

2

ax.boxplotは、ボックスプロット内のすべての要素の辞書を返します。その辞書からここに必要な鍵は'fliers'です。

boxdict['fliers']には、フライヤーをプロットするために使用されるLine2Dのインスタンスがあります。 .get_xdata().get_ydata()を使用して、xyの位置を取得できます。

setを使用してすべての一意のyの場所を見つけて、.count()を使用してその場所にプロットされたチラシの数を見つけることができます。

matplotlibのax.textを使用して、プロットにテキストラベルを追加する場合にのみ使用します。

import matplotlib.pyplot as plt 
import numpy as np 

# Some fake data 
data = np.zeros((10000, 2)) 
data[0:4, 0] = 1 
data[4:6, 0] = 2 
data[6:10, 0] = 3 
data[0:9, 1] = 1 
data[9:14, 1] = 2 
data[14:20, 1] = 3 

# create figure and axes 
fig, ax = plt.subplots(1) 

# plot boxplot, grab dict 
boxdict = ax.boxplot(data) 

# the fliers from the dictionary 
fliers = boxdict['fliers'] 

# loop over boxes in x direction 
for j in range(len(fliers)): 

    # the y and x positions of the fliers 
    yfliers = boxdict['fliers'][j].get_ydata() 
    xfliers = boxdict['fliers'][j].get_xdata() 

    # the unique locations of fliers in y 
    ufliers = set(yfliers) 

    # loop over unique fliers 
    for i, uf in enumerate(ufliers): 

     # print number of fliers 
     ax.text(xfliers[i] + 0.03, uf + 0.03, list(yfliers).count(uf)) 

plt.show() 

enter image description here

は、次の例を考えてみましょう

関連する問題

 関連する問題