Drawing

The drawing procedure is implemented in R because it supports different output formats. The Python procedure will provide additional options.

plotTime <- function(L,tMin,tMax,times,lTimes,wMax,file="testPic.pdf",
  step=5,dt=10,h=60,PDF=FALSE,col="red",main="Temporal quantity"){
  l <- length(L); cexp <- 0.3; cext <- 0.5; tt <- 9
  a <- b <- c <- numeric(l)
  for(i in 1:l) {a[i] <- L[[i]][1]; b[i] <- L[[i]][2]; c[i] <- L[[i]][3]}
  k <- tMax-tMin; W <- (k+3)*dt; H <- h + 5*step
  if(PDF) {pdf(file,width=(W+10)/25.4,height=(H+10)/25.4);
    cexp <- 0.5; cext <- 0.8; tt <- 3}
  x <- c(0,W); y <- c(0,H)
  plot.new()
  plot.window(xlim=x,ylim=y,asp=1,xlab="",ylab="")
  title(main=main)
  lines(c(0,W-dt),c(3*step,3*step))
  xp <- (1:(k+1))*dt; yp <- rep(3*step,k+1)
  points(xp,yp,pch=16,cex=cexp)
  if(length(times)>0) text((times-tMin+1)*dt-tt,rep(1.75*step,length(times)),
    lTimes[times-tMin+1],cex=cext,pos=4)
  text(-tt,0.5*step,paste("wMax =",wMax),cex=cext,pos=4)
  rect((a-tMin+1)*dt,rep(3*step,l),(b-tMin+1)*dt,c*(h/wMax)+3*step,col=col)
  if(PDF) dev.off()
}

The data are exchanged between Python and R in the JSON format.

setwd("C:/Users/batagelj/work/Python/WoS/SN5/time")
source("C:\\Users\\batagelj\\work\\Python\\WoS\\SN5\\time\\plotTime.R")
library(rjson)
Z <- fromJSON(file="comp.json")
names(Z)

tMin <- 1970; tMax <- 2008; lTimes <- tMin:tMax
times <- c(1970,1975,1980,1985,1990,1995,2000,2005,2008)
fiz <- Z[[3]]; wMax <- 2
plotTime(fiz,tMin,tMax,times,lTimes,wMax,h=200,main="Fiziki")
p <-Z[[6]]
plotTime(p,tMin,tMax,times,lTimes,wMax,h=160,main="Pat")
bdfc <- Z[[1]]; wMax <- 2
plotTime(bdfc,tMin,tMax,times,lTimes,wMax,h=200,main="SN5: Batagelj, Doreian, Ferligoj")
plotTime(bdfc,tMin,tMax,times,lTimes,wMax,h=200,main="SN5: Batagelj, Doreian, Ferligoj",
 file="BDF.pdf",PDF=TRUE)
wallc <- Z[[2]]; wMax <- 9
plotTime(allc,tMin,tMax,times,lTimes,wMax,h=200,main="SN5: All-All")
plotTime(allc,tMin,tMax,times,lTimes,wMax,h=200,main="SN5: All-All",PDF=TRUE,file="allc.pdf")

S <- fromJSON(file="socnet.json")
wMax <- 1
plotTime(S$Cn[[46]][[81]],tMin,tMax,times,lTimes,wMax,h=160,main="Batagelj, Ferligoj")
plotTime(S$Cn[[46]][[81]],tMin,tMax,times,lTimes,wMax,h=160,main="Batagelj, Ferligoj",PDF=TRUE)

bdf.pdf

allc.pdf

tq/time/draw.txt · Last modified: 2016/05/26 09:08 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki