Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

python - Radial animated plots

I am quite amazed by this radial animated visualization (of daily number of deaths in France over years) by Baptiste Coulmont, and I would love to make my own plots of this kind.

????????????????????radial animated plot (screenshot)

It seems the author produced it with R. I wonder if this is feasible directly within gnuplot, or if it requires programming in a general-purpose language.

question from:https://stackoverflow.com/questions/65651373/radial-animated-plots

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following could serve as starting point for a gnuplot implementation. In order to animate check the following answer. There seems to an issues of clipping the polar graph when autoranging, i.e. set rrange [0:*], which doesn't seem to be present when you set a fixed range, e.g. set rrange [0:1000]. There is certainly room for adaptions and improvements.

Code:

### 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

Result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...