用OpenGL从矩阵绘制热图的最有效方法? [英] Most efficient way of drawing a heatmap from matrix with OpenGL?
本文介绍了用OpenGL从矩阵绘制热图的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假定一个整数值的矩阵m
:
Assume a matrix m
of integer values:
m <- matrix(sample(1:10, 100, replace = TRUE), nrow = 10)
给出一个将这些值从1到10映射为某些颜色的调色板,如何在R中使用OpenGL图形将矩阵m
显示为热图,例如使用rgl
包? (最好以最有效的方式.)
Given a colour palette that maps those values from 1 to 10 to some colours, how to show matrix m
as a heatmap in R with OpenGL graphics, e.g. using the rgl
package? (Preferably in the most efficient way.)
推荐答案
The very thorough answer here suggests this may not be what you want; you might want to try the solution below against the other solutions benchmarked there. Nonetheless:
设置数据和颜色图
set.seed(101)
library(viridisLite)
vv <- viridis(10)
m <- matrix(sample(1:10, 100, replace = TRUE), nrow = 10)
绘制图片:
library(rgl)
view3d(theta=0, phi=0) ## head-on view
par3d(zoom=0.7) ## (almost) fill window
surface3d(x = 1:10, y = 1:10, z = matrix(0, 10,10),
color = vv[m],
smooth=FALSE, lit=FALSE ## turn off smoothing/lights
)
您可能需要在两个表面之间使用pop3d()
来清除前一个表面...
You may need to use pop3d()
between surfaces to clear the previous surface ...
这篇关于用OpenGL从矩阵绘制热图的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文