基本的に、ヒストグラムを作成したデータがいくつかあります。そこに大きな問題はありませんが、使用するだけですしかし、基本的にヒストグラムバー/ビン(専門用語が何であれ)がなるmatplotlib.pyplot.hist(data,bins=num)
一種のソーベルエッジ検出を行いたいです
私はあなたができることを見つけました/見つけました(私のデータはカラム化された txt ファイル)ith
-2*(i-1)th+0*(i)th+2*(i+1)th
import matplotlib.pyplot as plt
alldata = np.genfromtxt('filename', delimiter=' ')
data = alldata[:,18]
n,bins,patches = plt.hist(data,bins=30)
どちらが返す/与える
>>> n
array([3,0,3,3,6,1,...etc])
>>> bins
array([13.755,14.0298,14.3046,... etc])
>>> patches
<a list of 30 Patch objects>
ここで、操作を実行してn
、ソーベル フィルター処理されたものを取得できます (補足: 配列に対してこれを繰り返し行うだけです。次のような簡単な方法はありa = [-2,0,2]
ますか?)
だから、私の質問と問題! 結果をヒストグラムまたはラインプロットとして再構築する方法がわかりません...そして同じ水平軸を維持しますbins
アップデート
これが、ここまで取得するために使用するコードです。データダウンロードはこちら
import numpy as np
import matplotlib.pyplot as plt
# ignore this, it is so it makes it easier to iterate over later.
filNM = 'S_MOS152_cut'
filID = filNM + '.txt'
nbins = 30
# extract the data from file
stars = np.genfromtxt(filID, delimiter=' ')
imag = stars[:,18]
# let's start the histogram dance
n,bins,patches = plt.hist(imag, bins=nbins)
# now apply the edge filter (manually for lack of a better way)
nnew=[0 for j in xrange(nbins)]
for i in range(0,len(n)):
if i==0:
nnew[i]=2*n[i+1]
elif i==len(n)-1:
nnew[i]=-2*n[i-1]
else:
nnew=-2*n[i-1]+2*n[i+1]
np.array(nnew)
# I do this because it now generates the same form
# output as if you just say >>> print plt.hist(imag, bins=nbins)
filt = nnew,bins,patches
print filt