【问题标题】:2d surface plot in 3d. Plotting the indices of the peak on the graph (possibly by identifying the peaks ?). Python3d 中的 2d 曲面图。在图表上绘制峰值的索引(可能通过识别峰值?)。 Python
【发布时间】:2013-06-23 09:49:56
【问题描述】:

我正在尝试使用 mplot3d 模块在 3d 中绘制 2D 曲面图。

我知道如何“手动”找到最大值及其位置(就行和列而言),这对我正在做的事情非常重要。有没有办法将这些信息绘制到峰值上?也就是在峰值旁边写(maxval,row,col)?

附:当我问这个的时候。也许有一种简单的方法可以识别第二个峰值(或任何其他峰值?)。我目前正在使用掩码,以掩盖第一个峰并找到第二个峰,但我必须非常小心选择侧面,因为如果我碰巧掩盖的太少,一些非峰的东西会被识别出来作为一个峰值,真正的第二个峰值将不会被识别,从而扰乱了称为“峰峰值”信噪比的测量。

Surface Plot

我目前使用的代码是:

frame_a = gdal.Open( "frame_{0:05d}.tif".format(274) ).ReadAsArray()
# in case this helps, this is how the images are read, they are 16-bit GS tiffs.    
frame_b = gdal.Open( "frame_{0:05d}.tif".format(287) ).ReadAsArray()


#this does some clever stuff but basically it returns a 2-D 32x32 array.
corr = correlate_windows( windows_a[99], windows_b[99], corr_method = corr_method, nfftx=nfftx, nffty=nffty )

#this is how I find the position of max value.
column = np.argmax(np.max(corr, axis=0))
row = np.argmax(np.max(corr, axis=1))
maximum = corr.max()
print 'column = ' + str(column)
print 'row = ' +str(row)
print 'peak_1 = ' + str(maximum)



import matplotlib.cm as cmps
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import LinearLocator, FormatStrFormatter

fig = pl.figure()

ax = Axes3D(fig)

# window size is 32 in this case

nx, ny = window_size*2, window_size*2

xx = range(nx)

yy = range(ny)

X, Y = np.meshgrid(xx, yy)

ax.plot_surface(X , Y , corr , rstride = 1, cstride = 1 )

pl.show()

【问题讨论】:

  • 作为内务记录,您不能包含图片,除非您有更高的声誉并且有足够的代表您可以编辑其他帖子。
  • “松散对齐”是什么意思?你能在某个地方放第二张图片吗?您应该将问题的第二部分和第三部分分成各自的问题。理想的 SO 主题只有一个问题,这使得回答更容易,对未来的读者更有用。
  • 感谢 cmets tcaswell !我编辑了这个问题。我认为我在问题的另一部分(现已删除)中寻找的实际上是固定情节上的“观点”(在上图中,您无法真正看到零在哪里)。我认为这应该很容易找到。
  • 我没有时间写一个真正的答案,但我认为你可以用annotate做你想做的事

标签: python-2.7 matplotlib max axes mplot3d


【解决方案1】:

关于您的第二个问题,您可能会发现以下帖子很有用

Peak-finding algorithm for Python/SciPy

在我所做的一些工作中,我们使用了一个简单的导数近似值,当这个变化表明你有一个峰值(在一维数据中)时,可以添加一些参数来消除由于噪声引起的峰值。要将其扩展到 2D,我已经阅读了有关遵循梯度(向上或向下)直到达到最大值的算法。这些可能相当棘手,因为很容易陷入局部最小值/最大值。如果您对此进行跟进,请在此处链接,因为我想看看人们想出什么。

【讨论】:

  • 啊,当然 - 微积分才是王道!现在我明白了为什么这个问题应该只有一个问题......
猜你喜欢
  • 1970-01-01
  • 2018-05-29
  • 1970-01-01
  • 2013-11-14
  • 1970-01-01
  • 2020-11-11
  • 2016-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多