5

SOのアイデアを確認するためにこれを言い直しました(Michael0x2aに感謝)

にプロットされたヒストグラムの最大値に関連付けられた x 値を見つけようとしていますmatplotlib.pyplot。最初は、コードを使用してヒストグラムのデータにアクセスする方法を見つけることさえ困難でした

import matplotlib.pyplot as plt

# Dealing with sub figures...
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(<your data>, bins=<num of bins>, normed=True, fc='k', alpha=0.3)

plt.show()

次に、オンラインで(およびこれらのフォーラムの周りで)読んだ後、次のようにヒストグラムデータを「抽出」できることがわかりました。

n, bins, patches = ax.hist(<your data>, bins=<num of bins>, normed=True, fc='k', alpha=0.3)

bins基本的に、最大値が対応する値を見つける方法を知る必要がありますn!

乾杯!

4

3 に答える 3

7
import matplotlib.pyplot as plt
import numpy as np
import pylab as P

mu, sigma = 200, 25
x = mu + sigma*P.randn(10000)

n, b, patches = plt.hist(x, 50, normed=1, histtype='stepfilled')

bin_max = np.where(n == n.max())

print 'maxbin', b[bin_max][0]
于 2013-12-20T10:43:43.380 に答える
7

関数を使用してこれを行うこともできnumpyます。

elem = np.argmax(n)

これは、Python ループ ( doc )よりもはるかに高速です。

これをループとして書きたい場合は、そのように書きます

nmax = np.max(n)
arg_max = None
for j, _n in enumerate(n):
    if _n == nmax:
        arg_max = j
        break
print b[arg_max]
于 2013-09-16T05:53:41.363 に答える
0

これは、単純な「find-n-match」のようなアプローチで実現できます。

import matplotlib.pyplot as plt

# Yur sub-figure stuff
fig = plt.figure()
ax = fig.add_subplot(111)
n,b,p=ax.hist(<your data>, bins=<num of bins>)

# Finding your point
for y in range(0,len(n)):
    elem = n[y]
    if elem == n.max():
     break
else:   # ideally this should never be tripped
    y = none
print b[y] 

b「x値」リストもそうです 。ホープにb[y]対応する「x値」が役立ちます!n.max()

于 2013-09-16T00:27:02.400 に答える