Ian*_*low 15 python plot visualization matplotlib
是否有任何python库可以让我绘制z = f(x,y),其中z表示为密集光栅化图像中的颜色(与一堆散点图的颜色相对)?如果是这样,我会使用什么功能?
看起来matplotlib.pyplot中的一些轮廓函数接近我想要的,但它们绘制轮廓线,我不希望这样.
这里有一个具体的简单的例子(工作也不能采取矩阵参数的功能x和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()
Run Code Online (Sandbox Code Playgroud)
看一下pcolor或imshow在里面的文档matplotlib.
另一个好的开始是看看matplotlib画廊,看看是否有一个符合你要求的情节类型,然后使用示例代码作为你自己工作的起点:
http://matplotlib.sourceforge.net/gallery.html