時序圖的繪製—使用Gnuplot

來源:互聯網
上載者:User

時序圖的繪製—使用Gnuplot

時序圖是常見的一種資料繪圖,最典型的時序資料是天氣資料,天氣溫度、濕度等都是隨著時間變化的,本文給出一個例子是以LAMOST氣象站採集的一段時間資料,使用gnuplot繪出即時溫濕度變化曲線。

天氣資料:

timemjdtemp   rhumpres  wind_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
%s UNIX時間
%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 "\n時間"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 "\n時間"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

本文永久更新連結地址:

相關關鍵詞:
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.