所以我有代码绘制了我的数据集的二维图。我绘制它像这样:删除数据在散点图(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')
我已经试过与变数,但是我的一些变化运行的环实际上并不了解或不知道如何使其发挥作用。
所以我才正确地理解这一点,你想通过数据的一些数据的散点图和线然后你想要删除该行下面的所有点?或者可能以不同的颜色? –
你好!您的第一个解释是正确的 - 我希望移除该行下面的所有数据,因为我想对该行上面的数据进行进一步分析。 –