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
967 views
in Technique[技术] by (71.8m points)

linux - Use gnuplot to plot sqlite database

I have a sqlite database that contains basic weather information in the following format:

temp1 temp2 pressure humidity
22    23    1024     40
24    25    1027     45
25    26    1020     62
18    15    1019     80

how can I plot this data using gnuplot? Do I have to re-arrange the data before being able to plot it?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

To extract the data from your sqlite database, you can use the sqlite3 command line tool to extract the data on-the-fly. This is done with gnuplot by using a < which spawns a shell and uses the output of the given shell commands for plotting.

plot '< sqlite3 myfile.db3 "SELECT temp1, temp2, pressure, humidity FROM myTable;"' using 0:1 title 'temp1', 
     '' using 0:2 title 'temp2'

This would extract all four fields for each plot ('' repeats the previous file name / shell command). You could also use function to format the shell command:

SqliteField(f) = '< sqlite3 myfile.db3 "SELECT '.f.' from myTable;"'
fields = 'temp1 temp2 pressure humidity'
plot for [f in fields] SqliteField(f) using 0:1 title f

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

...