python 3d图如何改变视角,如何在Python中将3D功能绘制为2D色彩图?

Are there any python libraries that will let me plot z = f(x,y) where z is represented as the color in a densely rasterized image (as opposed to the color of a bunch of scatterplot points) ? If so, what function do I use?

It looks like some of the contour functions in matplotlib.pyplot come close to what I want, but they draw contour lines and I don't want that.

解决方案

here's a concrete simple example (works also for functions which can't take matrix arguments for x and y):

# the function to be plotted

def func(x,y):

# gives vertical color bars if x is horizontal axis

return x

import pylab

# define the grid over which the function should be plotted (xx and yy are matrices)

xx, yy = pylab.meshgrid(

pylab.linspace(-3,3, 101),

pylab.linspace(-3,3, 111))

# indexing of xx and yy (with the default value for the

# 'indexing' parameter of meshgrid(..) ) is as follows:

#

# first index (row index) is y coordinate index

# second index (column index) is x coordinate index

#

# as required by pcolor(..)

# fill a matrix with the function values

zz = pylab.zeros(xx.shape)

for i in range(xx.shape[0]):

for j in range(xx.shape[1]):

zz[i,j] = func(xx[i,j], yy[i,j])

# plot the calculated function values

pylab.pcolor(xx,yy,zz)

# and a color bar to show the correspondence between function value and color

pylab.colorbar()

pylab.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值