如何将数学函数绘制为热图 [英] How to plot a maths function as a heatmap

查看:54
本文介绍了如何将数学函数绘制为热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 x 和 y 可以在 0 到 10 之间变化,我如何将数学函数 z = x*(y^2) 绘制为图像图或热图?x 和 y 应位于各自的轴上,z 值应在绘图上显示为颜色.我可以找到只绘制离散值而不是连续函数的方法.谢谢你的帮助.

If x and y can vary from 0 to 10, how can I plot a maths function z = x*(y^2) as an image plot or heatmap ? The x and y should come to their respective axes and z value should be shown as colour on the plot. I could find method to plot only discrete values, not a continuous function. Thanks for your help.

推荐答案

例如

library(emdbook)
curve3d(x*y^2,xlim=c(0,10),ylim=c(0,10),sys3d="image")

curve3d 只是一个包装器(sys3d 参数为您提供了一系列绘图可能性)——更一般地说,您可以创建一个函数并使用 outer()(如果它是矢量化的)来创建一个矩阵,例如

curve3d is just a wrapper (the sys3d argument gives you a range of plotting possibilities) -- more generally, you can create a function and use outer() (if it's vectorized) to create a matrix, e.g.

xvec <- yvec <- seq(0,10,length.out=41)
z <- outer(xvec,yvec,function(x,y) x*y^2)
image(xvec,yvec,z)

这篇关于如何将数学函数绘制为热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆