所以我有代碼繪製了我的數據集的二維圖。我繪製它像這樣:刪除數據在散點圖(Python)中的一條線下
histogram = plt.hist2d(fehsc, ofesc, bins=nbins, range=[[-1,.5],[0.225,0.4]])
我想只是看看上面一定行,雖然數據,所以我增加了以下內容,它只是正常工作:
counts = histogram[0]
xpos = histogram[1]
ypos = histogram[2]
image = histogram[3]
newcounts = counts #we're going to iterate over this
for i in range (nbins):
xin = xpos[i]
yin = ypos
yline = m*xin + b
reset = np.where(yin < yline) #anything less than yline we want to be 0
#index = index[0:len(index)-1]
countout = counts[i]
countout[reset] = 0
newcounts[i] = countout
不過,我現在需要通過該切割區域繪製迴歸線。在plt.2dhist中這樣做是不可能的(AFAIK),所以我使用plt.scatter。問題是我不知道如何使這個切割 - 我不能索引scatterplot。
我現在有這樣的:
plt.xlim(-1,.5)
plt.ylim(.225, .4)
scatter = plt.scatter(fehsc,ofesc, marker = ".")
,我只希望保留一些上面一行的數據:
xarr = np.arange(-1,0.5, 0.015)
yarr = m*xarr + b
plt.plot(xarr, yarr, color='r')
我已經試過與變數,但是我的一些變化運行的環實際上並不瞭解或不知道如何使其發揮作用。
所以我才正確地理解這一點,你想通過數據的一些數據的散點圖和線然後你想要刪除該行下面的所有點?或者可能以不同的顏色? –
你好!您的第一個解釋是正確的 - 我希望移除該行下面的所有數據,因爲我想對該行上面的數據進行進一步分析。 –