从Scipy插值数据中提取线

时间:2015-03-12 15:51:05

标签: python numpy matplotlib scipy

我正在尝试从插值数据中绘制配置文件。首先,我的数据是三列x,y,c。

首先,我使用以下方法将数据插入到常规网格中:

  xi , yi = np.linspace(np.min(X), np.max(X),300) , np.linspace(np.min(Y), np.max(Y),300)
  xi, yi = np.meshgrid(xi, yi)
  zi = scipy.interpolate.griddata((X, Y), C , (xi, yi),method='nearest')

现在跟随线程:How to extract an arbitrary line of values from a numpy array?

我想绘制X = 5的值,Y = -4,4

  x0, y0 = 5, -4 # These are in _pixel_ coordinates!!
  x1, y1 = 5, 4
  num = 50
  x, y = np.linspace(x0, x1, num), np.linspace(y0, y1, num)
  #Getting values at that location
  zi2 = scipy.ndimage.map_coordinates(np.transpose(zi), np.vstack((x,y)))
  #Plotting 

  fig, axes = plt.subplots(nrows=2)
  axes[0].imshow(zi, vmin=np.min(C), vmax=110, origin='lower',extent=      [np.min(X), np.max(X), np.min(Y), np.max(Y)])
  axes[0].plot([x0, x1], [y0, y1], 'ro-')
  axes[0].axis('image')

  axes[1].plot(y,zi2)

  plt.show()

我得到的下图与轮廓的行为方式看起来不一样。

plot output

0 个答案:

没有答案