径向动画图
Radial animated plots
我对 Baptiste Coulmont 的 this radial animated visualization(多年来法国每天的死亡人数)感到非常惊讶,我很想制作我自己的此类情节。
作者好像是用R写的不知直接在gnuplot中是否可行,还是需要用通用语言编程
以下内容可以作为 gnuplot 实现的起点。
为了动画检查以下 。自动调整量程时似乎存在剪裁极坐标图的问题,即 set rrange [0:*]
,当您设置固定范围时似乎不存在,例如set rrange [0:1000]
。当然还有调整和改进的空间。
代码:
### radial animated plot
reset session
# create some random test data
# Gauss curve by specifing Amplitude A, position x0 and width via FWHM
GaussW(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
myTimeFmt = "%d.%m.%Y"
StartDate = "01.01.2018"
EndDate = "31.12.2020"
t0=int(strptime(myTimeFmt,StartDate))
t1=int(strptime(myTimeFmt,EndDate))
SecPerDay = 3600*24
set print $Data
do for [t=t0:t1:SecPerDay] {
Date = strftime(myTimeFmt,t)
y0 = rand(0)*200+400
y1(t) = GaussW(t,strptime(myTimeFmt,"01.02.2020"),100,SecPerDay*30)
y2(t) = GaussW(t,strptime(myTimeFmt,"01.04.2020"),300,SecPerDay*10)
y3(t) = GaussW(t,strptime(myTimeFmt,"10.10.2020"),400,SecPerDay*30)
print sprintf("%s %g",Date,y0+y1(t)+y2(t)+y3(t))
}
set print
DaysInMonth(t) = int(strftime("%d",strptime("%m.%Y",sprintf("%02d.%04d",tm_mon(t)+2,tm_year(t)))-1))
DateToAngle(t) = tm_mday(t)/DaysInMonth(t)*30 + tm_mon(t)*30
MonthToAngle(m) = (m-1)*30 # m=1 to 12
myDate(col) = DateToAngle(strptime(myTimeFmt,strcol(col)))
myColor(col) = tm_year(strptime(myTimeFmt,strcol(col)))
# extract the available years from data into table
set table $Legend
unset polar
plot $Data u (tm_year(strptime(myTimeFmt,strcol(1)))):(1) smooth freq
set polar
unset table
set size ratio -1
set polar
set theta clockwise top
set angle degrees
set grid
set border 0 polar
unset raxis
unset xtics
set ttics 30
set format r ""
set rtics scale 0,0
# month labels
myMonth(i) = strftime("%b",i*SecPerDay*28)
do for [i=1:12] {
set ttics add (myMonth(i) MonthToAngle(i))
}
set key at screen 0.95, screen 0.95 right
set rrange[0:1000]
set ytics 0,200 scale 0,0 nomirror offset -4,0
set rtics 200
plot $Data u (myDate(1)):2:(myColor(1)) w l lc var notitle, \
for [i=5:|$Legend|-2] $Legend u (NaN):(NaN):1 every ::i-5::i-5 \
w l lw 2 lc var ti sprintf("%s", word($Legend[i],1))
### end of code
结果:
我对 Baptiste Coulmont 的 this radial animated visualization(多年来法国每天的死亡人数)感到非常惊讶,我很想制作我自己的此类情节。
作者好像是用R写的不知直接在gnuplot中是否可行,还是需要用通用语言编程
以下内容可以作为 gnuplot 实现的起点。
为了动画检查以下 set rrange [0:*]
,当您设置固定范围时似乎不存在,例如set rrange [0:1000]
。当然还有调整和改进的空间。
代码:
### radial animated plot
reset session
# create some random test data
# Gauss curve by specifing Amplitude A, position x0 and width via FWHM
GaussW(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
myTimeFmt = "%d.%m.%Y"
StartDate = "01.01.2018"
EndDate = "31.12.2020"
t0=int(strptime(myTimeFmt,StartDate))
t1=int(strptime(myTimeFmt,EndDate))
SecPerDay = 3600*24
set print $Data
do for [t=t0:t1:SecPerDay] {
Date = strftime(myTimeFmt,t)
y0 = rand(0)*200+400
y1(t) = GaussW(t,strptime(myTimeFmt,"01.02.2020"),100,SecPerDay*30)
y2(t) = GaussW(t,strptime(myTimeFmt,"01.04.2020"),300,SecPerDay*10)
y3(t) = GaussW(t,strptime(myTimeFmt,"10.10.2020"),400,SecPerDay*30)
print sprintf("%s %g",Date,y0+y1(t)+y2(t)+y3(t))
}
set print
DaysInMonth(t) = int(strftime("%d",strptime("%m.%Y",sprintf("%02d.%04d",tm_mon(t)+2,tm_year(t)))-1))
DateToAngle(t) = tm_mday(t)/DaysInMonth(t)*30 + tm_mon(t)*30
MonthToAngle(m) = (m-1)*30 # m=1 to 12
myDate(col) = DateToAngle(strptime(myTimeFmt,strcol(col)))
myColor(col) = tm_year(strptime(myTimeFmt,strcol(col)))
# extract the available years from data into table
set table $Legend
unset polar
plot $Data u (tm_year(strptime(myTimeFmt,strcol(1)))):(1) smooth freq
set polar
unset table
set size ratio -1
set polar
set theta clockwise top
set angle degrees
set grid
set border 0 polar
unset raxis
unset xtics
set ttics 30
set format r ""
set rtics scale 0,0
# month labels
myMonth(i) = strftime("%b",i*SecPerDay*28)
do for [i=1:12] {
set ttics add (myMonth(i) MonthToAngle(i))
}
set key at screen 0.95, screen 0.95 right
set rrange[0:1000]
set ytics 0,200 scale 0,0 nomirror offset -4,0
set rtics 200
plot $Data u (myDate(1)):2:(myColor(1)) w l lc var notitle, \
for [i=5:|$Legend|-2] $Legend u (NaN):(NaN):1 every ::i-5::i-5 \
w l lw 2 lc var ti sprintf("%s", word($Legend[i],1))
### end of code
结果: