Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is gnuplot better for the use cases demonstrated on the page here?

I've always avoided gnuplot because it has looked pretty hard to get anything useful out of. But uplot looks much more approachable. Just piping some data to "uplot hist --nbins 20" is something I'll remember.



You just need a better frontend. A distribution of file sizes < 100kB in my home directory:

  ls -l                            \
  | awk '$5 < 100000 {print $5}'   \
  | feedgnuplot                    \
      --histo 0                    \
      --binwidth 5000              \
      --xlabel 'File size (bytes)' \
      --ylabel Frequency           \
      --terminal 'dumb 120 40'     \
      --unset grid

     45 +-----------------------------------------------------------------------------------------------------------+
        |  *      *   +            +             +            +             +            +             +            |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     40 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     35 |***      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     30 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     25 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     20 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     15 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
     10 |-+*      *                                                                                               +-|
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
        |  *      *                                                                                                 |
      5 |-+*      ********                                                                                        +-|
        |  *      *      *                                              ********                                    |
        |  *      *      ********     **********************     ********      *                                    |
        |  *      *   +  *      *  +  *      *   +  *      *******      *   +  *         +             +  ********  |
      0 +-----------------------------------------------------------------------------------------------------------+
        0           10000        20000         30000        40000         50000        60000         70000        80000
                                                      File size (bytes)
Usually you want graphical output, but it does fine in ascii


Oh hey Dima.

Feedgnuplot is really slick.

https://github.com/dkogan/feedgnuplot

It's in the debian repos too.


I don’t actually get much chance to use gnuplot, but it can plot data from a pipe. The syntax is a bit more involved as I recall.


Within the gnuplot shell you use `<` at the start of a "filename" like

    gnuplot> plot '<pipeline'
It just uses system(3) for "pipeline". So, technically you could have a whole script in there with maybe tricky gnuplot-quoting/escaping of shell stuff.

You do have 2 different history logs this way - the shell one and the plot one while the uplot way is integrated.

If you really want integrated, you could drive gnuplot with temp files, though each shell command-line would probably have to pass a lot of controls. E.g.,

    #!/bin/sh
    cat > /tmp/dat          # should use mktemp -d
    cat > /tmp/p.gpi <<-EOF
    plot '/tmp/dat' $*
    EOF
    gnuplot /tmp/p.gpi
and then

    $ seq 1 10 | gpl with lines
It is an exercise for the reader (well, it has probably been done N times...) to harden the temp paths, clean up afterward, generalize to source user/maybe per-directory `foo.gpi` setup and so on.

In the unlikely event temp space is actually any sort of issue then you might be able to use mkfifo (I've never tried) or else generate a .gpi script that uses the plot '<string' syntax escaping `string`.


No need for any of that; gnuplot can just read from the pipe directly: `seq 1 10 | gnuplot -e "plot '<&2'"`


Nice! Added in 2008, if anyone is curious. (EDIT: and in db48x's comment already[1]) Also, I had to put in a `cat` to make it work:

    seq 1 10 | gnuplot -e "plot '<cat' with lines"
[1] https://news.ycombinator.com/item?id=34365290


Oh, that goes to show you how little I use it. I read the documentation and merely assumed that it would work for stdin, but gnuplot exits with an error in that case. This will work, but it’s pretty funky:

    gnuplot -e "set terminal sixelgd;plot '<&3' with lines" 3< <(seq 1 10)
Good luck remembering that!


No need of cat. You can use filename "-" to mean standard input:

    seq 1 10 | gnuplot -e 'plot "-"'




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: