使用gnuplot绘制sqlite数据库 [英] Use gnuplot to plot sqlite database

查看:206
本文介绍了使用gnuplot绘制sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sqlite数据库,其中包含以下格式的基本天气信息:

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

如何使用 gnuplot 绘制这些数据?

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

推荐答案

要从sqlite数据库中提取数据,您可以使用 sqlite3 命令行工具即时提取数据。这通过使用gnuplot通过使用< 来完成,它生成一个shell并使用给定shell命令的输出进行绘图。

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'

这将提取每个图的所有四个字段(''文件名/ shell命令)。您还可以使用函数格式化shell命令:

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

这篇关于使用gnuplot绘制sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆