python划分网格区域_python – 如何将2D网格点云插入连续区域?

tricontouf

您可以使用有效值的三角图.为此,您首先需要过滤掉所有的nan值(您应该确实使用无效值np.nan而不是None).

可以将这些值及其坐标放入plt.tricontour()中以获得等高线图而无需手动插值.

import matplotlib.pyplot as plt

import numpy as np

# Generate some example data

f = lambda x,y : np.exp((-(x-150)**2-(y-150)**2)/3.e3)

plotGrid = np.zeros((300,300))*np.nan

coo = np.random.randint(5,295, size=(150,2) )

for x,y in coo:

plotGrid[y,x] = f(x,y)

#plotGrid is now a numpy.ndarray with shape (300,300), mostly np.nan, and dtype float

# filter out nan values and get coordinates.

x,y = np.indices(plotGrid.shape)

x,y,z = x[~np.isnan(plotGrid)], y[~np.isnan(plotGrid)], plotGrid[~np.isnan(plotGrid)]

plt.tricontourf(x,y,z)

plt.colorbar()

plt.show()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值