R';s tikzDevice处理光栅图像?

R';s tikzDevice处理光栅图像?,r,image,raster,tex,tikz,R,Image,Raster,Tex,Tikz,我读过,如果tikz采用光栅图像,它将被存储为png。有了这些,tikz生成了它周围的其余图形,并再次将光栅图像包含在最终的tex文件中 现在我有以下几点: pic <- T if(pic) { tikz(file=paste(plotpath,"Rohdaten_S1_S2_D21.tex",sep=""),width=width,height=height,engine = "pdftex",) #png(filename=paste(plotpath,"Rohdaten_S1

我读过,如果tikz采用光栅图像,它将被存储为png。有了这些,tikz生成了它周围的其余图形,并再次将光栅图像包含在最终的tex文件中

现在我有以下几点:

pic <- T
if(pic)
{
  tikz(file=paste(plotpath,"Rohdaten_S1_S2_D21.tex",sep=""),width=width,height=height,engine = "pdftex",)
  #png(filename=paste(plotpath,"Rohdaten_S1_S2_D6.png",sep=""),width=width,height=height,res=res,units="in")
  par(mfrow=c(2,1),mar=c(1.1,3,2,0),mgp=c(1.5,0.5,0),ps=f.size,cex=1,xaxt="n")
}
if(!pic) par(mfrow=c(2,1),mar=c(1,4,3,0))
for(i in 1:2)
{
  x <- sensors[[i]]$time
  y <- sensors[[i]]$depth
  z <- sensors[[i]]$velo
  image(x,y,z)
  #   plot.image(x,y,z
#              ,xlim=c(max(x)-400,max(x)),zlim=2*c(-1,1)
#              ,xlab="",ylab="$d/\\mathrm{m}$",zlab="$v/(\\mathrm{mm/s})$"
#              ,z.adj=c(0,0),ndz=5,z.cex=1
#              )  
  abline(v=(1:10)/0.026+par("usr")[1],lty=2)
  if(!pic) abline(h=(1:floor(max(y/0.02)))*0.02)
  mtext(text=paste("Sensor",i),side=3,line=0.1,adj=0)
  par(mar=c(3,3,0.1,0),xaxt="s")
}
title(xlab="t/s")
if(pic) dev.off()

pic解决方案非常简单,但并不明显

  • R
    中的
    image()
    -函数首先生成矢量图形 例如。有一个开关
    image(…,useRaster=T)
    ,用于 可以强制使用
    image()
    -函数生成光栅图形
  • image()
    -函数表示规则网格(二次像素)。否则会发生错误
  • 如何获得规则网格

    假设有一个坐标为x[],y[]和标量矩阵z[,]的图像。然后可以计算重新采样的规则网格:

    x.new<-seq(min(xlim),max(xlim),length.out=dim.max[1])
    y.new<-seq(min(ylim),max(ylim),length.out=dim.max[2])
    
    z<-apply(z,2,function(y,x,xout) return(approx(x,y,xout=xout+min(diff(x))/2,method="constant",rule=2)$y),x,x.new)
    z<-t(apply(z,1,function(y,x,xout) return(approx(x,y,xout=xout+min(diff(x))/2,method="constant",rule=2)$y),y,y.new))
    
    tikz(file ='a.tex',width = 2, height = 2)
        image(x,y,z,useRaster = T)
    dev.off()
    

    x.new解决方案非常简单,但并不明显

  • R
    中的
    image()
    -函数首先生成矢量图形 例如。有一个开关
    image(…,useRaster=T)
    ,用于 可以强制使用
    image()
    -函数生成光栅图形
  • image()
    -函数表示规则网格(二次像素)。否则会发生错误
  • 如何获得规则网格

    假设有一个坐标为x[],y[]和标量矩阵z[,]的图像。然后可以计算重新采样的规则网格:

    x.new<-seq(min(xlim),max(xlim),length.out=dim.max[1])
    y.new<-seq(min(ylim),max(ylim),length.out=dim.max[2])
    
    z<-apply(z,2,function(y,x,xout) return(approx(x,y,xout=xout+min(diff(x))/2,method="constant",rule=2)$y),x,x.new)
    z<-t(apply(z,1,function(y,x,xout) return(approx(x,y,xout=xout+min(diff(x))/2,method="constant",rule=2)$y),y,y.new))
    
    tikz(file ='a.tex',width = 2, height = 2)
        image(x,y,z,useRaster = T)
    dev.off()
    

    x.newit原来,它已经实现了!事实证明,它已经实现了!事实证明,它已经实现了!