如何使用像素矩阵在同一图上放置多个图像 [英] How to position multiple image on the same plot using a pixel matrix

查看:51
本文介绍了如何使用像素矩阵在同一图上放置多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用kaggle数据集在同一图上说明100个随机训练示例:

我不知道如何指定每个像素的位置....

谢谢!

解决方案

一种快速的解决方案是使用 par :

  par(mfrow = c(5,5),mar = c(0,0,0,0))for(i in sample(2:length(data),100,replace = FALSE)){dat<-matrix(as.numeric(data [i,1:784]/256),ncol = 28,nrow = 28,byrow = TRUE)图片(日期,轴=假,col =灰色(seq(0,1,长度= 256)))} 

如果要在外部边框,请将 par 中的 oma 设置为> 0.例如

  par(mfrow = c(5,5),mar = c(0,0,0,0),oma = c(2,2,2,2)) 

I am trying to illustrate 100 random training example on the same plot using the kaggle dataset you can found here : https://www.kaggle.com/c/digit-recognizer/data.

I am able to plot one after the other the number but not on the same plot :

  par(mfrow=c(5,5))

for(i in sample(2:length(data),100,replace=FALSE)){      
    dat <- matrix(as.numeric(data[i,1:784]/256),ncol=28,nrow=28,byrow=TRUE)
    image(dat, axes=TRUE,col=grey(seq(0,1,length=256)))
}

What I wanna do is something like this:

I am not able to figure out how to specify the location of each pixel....

Thank you !

解决方案

A quick solution would be to set margins (mar) to 0 using par:

par(mfrow=c(5,5), mar=c(0,0,0,0))

for(i in sample(2:length(data),100,replace=FALSE)){      
    dat <- matrix(as.numeric(data[i,1:784]/256),ncol=28,nrow=28,byrow=TRUE)
    image(dat, axes=FALSE,col=grey(seq(0,1,length=256)))
}

If you want border on the outside, set oma in par to values >0. E.g.

par(mfrow=c(5,5), mar=c(0,0,0,0), oma=c(2,2,2,2))

这篇关于如何使用像素矩阵在同一图上放置多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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