Welcome 微信登录

首页 / 数据库 / MySQL / 时序图的绘制—使用Gnuplot

时序图是常见的一种数据绘图,最典型的时序数据是天气数据,天气温度、湿度等都是随着时间变化的,本文给出一个例子是以LAMOST气象站采集的一段时间数据,使用gnuplot绘出实时温湿度变化曲线。天气数据:timemjdtemp rhumpreswind_avgwind_max wind_dir dewpoint2008-12-14 18:02:0078933242 -2.433915.52.64.276-16.462008-12-14 18:04:0078933244 -2.333915.62.84.675-16.382008-12-14 18:06:0078933246 -2.433915.62.74.680-16.462008-12-14 18:08:0078933248 -2.433915.62.75.275-16.462008-12-14 18:10:0078933250 -2.433915.53.87.178-16.462008-12-14 18:12:0078933252 -2.333915.63.36.476-16.382008-12-14 18:14:0078933254 -2.333915.62.85.974-16.382008-12-14 18:16:0078933256 -2.333915.53.5874-16.382008-12-14 18:18:0078933258 -2.333915.63.17.479-16.382008-12-14 18:20:0078933260 -2.333915.72.85.974-16.382008-12-14 18:22:0078933262 -2.334915.71.7480-16.022008-12-14 18:24:0078933264 -2.434915.72.64.176-16.112008-12-14 18:26:0078933266 -2.434915.82.5474-16.112008-12-14 18:28:0078933268 -2.333915.82.73.775-16.382008-12-14 18:30:0078933270 -2.233915.84.26.375-16.292008-12-14 18:32:0078933272 -2.133915.92.95.677-16.22008-12-14 18:34:0078933274 -2.234915.93.35.373-15.932008-12-14 18:36:0078933276 -2.234915.93.34.975-15.932008-12-14 18:38:0078933278 -2.234915.92.74.371-15.932008-12-14 18:40:0078933280 -2.234915.945.673-15.932008-12-14 18:42:0078933282 -2.133915.93.85.173-16.22008-12-14 18:44:0078933284 -2.133915.93.65.473-16.2...............曲线图中需要有中文的内容,因此必须先指定中文字体,下面例子是方正黑体,字号11,绘出的图是png格式,文件名w.png,图像大小1000x1000。时序数据必须指定时间的格式,下面例子的格式是:set timefmt "%Y-%m-%d %H:%M:%S"更多的时间格式为:
格式说明
%d日期:1-31
%m月份:1-12
%y年:0-99
%Y年,四位数
%j一年中的天数:1-365
%H小时:0-23
%M分钟:0-59
%sUNIX时间
%S秒:0-59
%b三个字母的月份缩写
%B月份名称
程序如下:set terminal png font "./font/fzht.ttf,11" size 1000,1000 set output "w.png"set multiplot layout 2, 1 title "LAMOST 天气信息"#set size ratio 0.4set title "LAMOST 天气信息 - 温度 露点温度 相对湿度图" font "./font/fzht.ttf,13"set xdata timeset xlabel " 时间"set ylabel "温度 / 露点温度 (C)"set timefmt "%Y-%m-%d %H:%M:%S"set grid#set yrange [-3:6]set y2label "相对湿度 (%)"set y2ticsplot "w.dat" using 1:4 with line title "温度", "w.dat" using 1:10 with line title "露点温度", "w.dat" using 1:5 axes x1y2 with line title "相对湿度"#set title "LAMOST 天气信息 - 风速 大气压图" font "./font/fzht.ttf,13"set xdata timeset xlabel " 时间"set ylabel "风速 (m/s)"set timefmt "%Y-%m-%d %H:%M:%S"set grid#set nokeyset y2label "大气压 (hPa)"set y2ticsplot "w.dat" using 1:8 with line title "瞬时最大风速", "w.dat" using 1:7 with line title "平均风速", "w.dat" using 1:6 axes x1y2 with line title "大气压"程序名称demo.gp,运行程序:gnuplot demo.gp效果图本文永久更新链接地址