python怎么画人像_谁知道怎么用 python 画等值面图啊?

8

2016-07-14 02:16:44 +08:00

不太清楚你的问题细节, 写了个 3d 插值的例子:

# -*- coding: utf-8 -*-

import numpy as np

from scipy.interpolate import interpn

from enthought.mayavi import mlab

mlab.options.offscreen = True

original_points = 20j

interp_points = 40j

figsize = (1280, 720)

x, y, z = np.mgrid[-15:14:original_points, -12:12:original_points, -14:15:original_points]

# x.shape: 20x20x20

# y.shape: 20x20x20

# z.shape: 20x20x20

s = np.sin(x*y*z)/(x*y*z) # s.shape: 20x20x20

mlab.contour3d(x, y, z, s)

mlab.savefig("original.png", size=figsize)

xs, ys, zs = np.mgrid[-15:14:interp_points, -12:12:interp_points, -14:15:interp_points]

# Construct a 3d array of 3-dimensional points.

arr_4d = np.concatenate((xs[..., None], ys[..., None], zs[..., None]), axis=3) # shape: 40x40x40x3

ss = interpn((x[:, 0, 0], y[0, :, 0], z[0, 0, :]), s, arr_4d, method="nearest")

# Weirdly though, this will also work, why?(゚д゚)

sss = interpn((x[:, 0, 0], y[0, :, 0], z[0, 0, :]), s, (xs, ys, zs), method="nearest")

print np.all(ss == sss) # True

mlab.contour3d(xs, ys, zs, ss)

mlab.savefig("interpolate.png", size=figsize)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值