YouTube
Source code (gnuplot, PLT file)
Development Environment- macOS Big Sur ver.11.1
- gnuplot version 5.4 patchlevel 4
This program outputs many PNG files. In order to get the animation, you need to convert images to a gif or movie file.
I always use FFmpeg and convert to mp4 file for YouTube.
Please refer to another my blog : Hiroloquy (written in Japanese).
Click “陽性者数” and “死亡者数” from the following link and download CSV files.
【English】Open data|Ministry of Health, Labour and Welfare
Click “No. of positive cases” and “No. of deaths” and download CSV files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reset | |
# -------------------- Functions ------------------- # | |
# Convert unix_time to date | |
unix2date(unix_time) = strftime("%Y/%m/%d", unix_time) | |
# Convert day to sec | |
day2sec(t) = 3600*24*t | |
# Round up at the i-th digit | |
ceil_i(x, i) = ceil(x/10.**(i-1))*10.**(i-1) | |
# -------------------- Setting ------------------- # | |
set term pngcairo enhanced size 1280, 720 font 'Times, 20' | |
folderName = 'image' | |
system sprintf("mkdir %s", folderName) # Make the folder | |
# Open data | |
data_txt = "pcr_positive_daily.csv" | |
data2_txt = "death_total.csv" | |
set timefmt "%Y/%m/%d" | |
set datafile separator "," # for csv file | |
# Calculate UTC using UNIX time | |
date0 = "2020/01/16" # First day | |
date0_unix = strptime("%Y/%m/%d", date0) # UNIX time [s] | |
# Get number and maximum of data | |
stat data_txt using 2 nooutput | |
data1_num = STATS_records; data1_ymax = STATS_max | |
stat data2_txt using 2 nooutput | |
data2_num = STATS_records; data2_ymax = STATS_max | |
data_num_high = data1_num; data_num_low = data2_num | |
if(data_num_high < data_num_low) data_num_high = data2_num; data_num_low = data1_num | |
date_lag = data_num_high - data_num_low | |
data_ymax_sup = data1_ymax | |
if(data1_ymax < data2_ymax) data_ymax_sup = data2_ymax | |
X_MAX_unix = date0_unix + day2sec(data1_num-1) # Last day | |
X_MAX = unix2date(X_MAX_unix) | |
Y_MAX = data_ymax_sup | |
set grid | |
set key left top Left box width -5 spacing 1.3 reverse | |
set xlabel "Date" offset 0, 1 | |
set ylabel "Number" | |
set timefmt "%Y/%m/%d" | |
set xdata time | |
set format x "%Y/%m/%d" | |
set xtics "2020/1/16", day2sec(20) offset -0.7, 0 rotate by -70 font ", 16" | |
set ytics offset 0, 0.3 | |
set xrange["2020/1/16":X_MAX] | |
set yrange[0:ceil_i(Y_MAX, 4)] | |
set style fill solid | |
# -------------------- Update and output images ------------------- # | |
do for[i=1:data_num_high]{ | |
set output sprintf("%s/img_%04d.png", folderName, i) | |
set title sprintf("%s", unix2date(date0_unix + 86400*(i-1))) font ', 22' | |
plotCommand = 'plot ' | |
plotCommand = plotCommand."data_txt every ::1::i using 1:2 with boxes fc rgb 'royalblue' title 'Positive PCR test cases (daily)'" | |
if(i > date_lag){ | |
l = i - date_lag | |
plotCommand = plotCommand.", data2_txt every ::1::l using 1:2 w l lw 2 lc rgb 'red' title 'Death (total)' " | |
plotCommand = plotCommand.", data2_txt every ::l::l using 1:2 w p ps 0.5 pt 7 lc rgb 'red' notitle" | |
} | |
eval plotCommand | |
set out | |
} |
References / Source
【Japanese】オープンデータ | 厚生労働省Click “陽性者数” and “死亡者数” from the following link and download CSV files.
【English】Open data|Ministry of Health, Labour and Welfare
Click “No. of positive cases” and “No. of deaths” and download CSV files.
No comments:
Post a Comment