如何在 python 中将 3D 函数绘制为 2D 颜色图?
是否有任何 python 库可以让我绘制 z = f(x,y) ,其中 z 表示为密集光栅化图像中的颜色(而不是一堆散点图点的颜色)?如果是这样,我该使用什么功能?
看起来 matplotlib.pyplot 中的一些轮廓函数接近我想要的,但它们绘制轮廓线,而我不想要这样。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了扩展我上面的评论,这里有一些在网格上计算函数的可能方法
To expand my comment above, here are some possible ways of computing a function on a grid
归根结底:这只是安德烈·霍尔兹纳的答案的一个微小变化。如果需要的话请为他点赞!
使用严格的最小数组维度和索引,语法可能更容易阅读。它依赖于以下一点(引自文档)。
如果 X 和 Y 之一或两者都是一维数组或列向量,它们将根据需要扩展为适当的二维数组,形成矩形网格。
To give credit where it's due: this is only a slight variation on Andre Holzner's answer. Please upvote him if you must!
The syntax is perhaps easier to read with the strict minimum of array dimensions and indices. It relies on the following point (quoted from the doc).
If either or both of X and Y are 1-D arrays or column vectors, they will be expanded as needed into the appropriate 2-D arrays, making a rectangular grid.
这是一个具体的简单示例(也适用于不能采用
x
和y
矩阵参数的函数):here's a concrete simple example (works also for functions which can't take matrix arguments for
x
andy
):查看
matplotlib
中pcolor
或imshow
的文档。另一个好的起点是查看 matplotlib 库,看看是否有与您要查找的内容相匹配的绘图类型,然后使用示例代码作为您自己工作的起点:
http://matplotlib.sourceforge.net/gallery.html
Take a look at the documentation for
pcolor
orimshow
inmatplotlib
.Another good place to start is take a look at the matplotlib gallery and see if there is a plot type that matches what you are looking for and then use the sample code as a jumping off point for your own work:
http://matplotlib.sourceforge.net/gallery.html