Skip to content
no0p edited this page Oct 15, 2014 · 5 revisions

Because gnuplot function executes arbitrary gnuplot commands, arbitrary plots can be generated.

It's a two step process: first create a data set, then apply the script.

Create gnuplot readable data set

Consider the following table from the introductory example.

robert=# select * from airquality limit 10;
 id | ozone | solar_r | wind | temp | month | day 
----+-------+---------+------+------+-------+-----
  1 | 41    | 190     |  7.4 | 67   | 5     | 1
  2 | 36    | 118     |    8 | 72   | 5     | 2
  3 | 12    | 149     | 12.6 | 74   | 5     | 3
  4 | 18    | 313     | 11.5 | 62   | 5     | 4
  5 |       |         | 14.3 | 56   | 5     | 5
  6 | 28    |         | 14.9 | 66   | 5     | 6
  7 | 23    | 299     |  8.6 | 65   | 5     | 7
  8 | 19    | 99      | 13.8 | 59   | 5     | 8
  9 | 8     | 19      | 20.1 | 61   | 5     | 9
 10 |       | 194     |  8.6 | 69   | 5     | 10
(10 rows)

Use the copy command to create a gnuplot readable file.

=# copy (select wind, temp from airquality limit 10) 
          to '/tmp/wind_temp.tsv';

The contents of the file should be put in the format readable by the gnuplot script.

$ cat /tmp/wind_temp.tsv
7.4     67
8       72
12.6    74
11.5    62
14.3    56
14.9    66
8.6     65
13.8    59
20.1    61
8.6     69

Execute gnuplot command


=# select gnuplot('plot "/tmp/wind_temp.tsv" using 1:2');

                            gnuplot                             
----------------------------------------------------------------
                                                               +
   74 ++-----+------+------+-A----+-----+------+------+-----++ +
      +      +      +  "/tmp/wind_temp.tsv" using 1:2 + A    + +
   72 ++     A                                              ++ +
      |                                                      | +
   70 ++                                                    ++ +
      |        A                                             | +
   68 ++                                                    ++ +
      |    A                                                 | +
   66 ++                             A                      ++ +
      |        A                                             | +
      |                                                      | +
   64 ++                                                    ++ +
      |                                                      | +
   62 ++                 A                                  ++ +
      |                                               A      | +
   60 ++                                                    ++ +
      |                          A                           | +
   58 ++                                                    ++ +
      +      +      +      +      +     +      +      +      + +
   56 ++-----+------+------+------+A----+------+------+-----++ +
      6      8      10     12     14    16     18     20     22+
                                                               +
 
(1 row)


Clone this wiki locally