Here is an example of feeding query output into gnuplot without leaving psql:
# psql -U postgres
psql (8.4.15)
Type "help" for help.
postgres=# \t
Showing only tuples.
postgres=# \a
Output format is unaligned.
postgres=# \f ' '
Field separator is " ".
postgres=# select * from example;
1 1
2 2
3 3
4 4
postgres=# \o | /usr/bin/gnuplot
postgres=# select 'set title "My Graph"; set terminal dumb 78 24; set key off; set ylabel "Time"; set xlabel "Servers";' || 'plot ''-'' with lines;' ; select * from example;
postgres=# \o
My Graph
Time
4 ++----------+----------+-----------+----------+-----------+---------**
+ + + + + + **** +
| **** |
3.5 ++ **** ++
| **** |
| **** |
3 ++ *** ++
| **** |
| **** |
2.5 ++ **** ++
| **** |
| **** |
2 ++ *** ++
| **** |
| **** |
1.5 ++ **** ++
| **** |
+ **** + + + + + +
1 **----------+----------+-----------+----------+-----------+---------++
1 1.5 2 2.5 3 3.5 4
Servers
postgres=#