Use gnuplot to plot sqlite database

前端 未结 1 870
Happy的楠姐
Happy的楠姐 2020-12-18 11:16

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

temp1 temp2 pressure humidity
22    23    1024     40
24    25    1         


        
相关标签:
1条回答
  • 2020-12-18 11:32

    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
    
    0 讨论(0)
提交回复
热议问题