Gnuplot interactive visualization

I have worked a lot with gnuplot during the past years. From visualizing latency to doing exploratory analytics on system metrics, this tool seems unstoppable. I have yet to find an area where it shows its limits.

Today I want to write about interactive visualization.

Presentation

Gnuplot is a portable command-line driven graphing utility for Linux, OSX and Windows. I must say it does not produce as pretty charts as d3.js. But for my use cases, it is definitely the right tool for the job.

Usual use case

The classic way of using gnuplot is to produce PNG images from a CSV-like dataset, this one for instance. To do that, we only need to type set term png along with set output 'my-image.png' and off we go.

The problem with this approach is that it is a static one. No zooming/dezooming capabilities, no tooltip when hovering some part of the curve. It is just an image that you can share once you have figured out what you wanted to know.

Gnuplot terminals

Terminals are what produces gnuplot output, and there are A LOT of them. Type set term to see the available ones. Let’s focus on these 3.

set term

Available terminal types:
aqua        Interface to graphics terminal server for Mac OS X
canvas      HTML Canvas object
png         PNG images using libgd and TrueType fonts

Using aqua will display a non-interactive image, that does not require to be stored on disk, unlike a PNG file. That is good, but not what I want.

However, canvas is a very handy one. It will produce a html page that allows to zoom/dezoom, click, and select the curves to display among the available ones. Try the two following scripts to get a feeling of how it can help you.

This one will produce a 800x600 PNG image with sin(x)

  set term png size 800,600
  set output "sin.png"
  set xrange [-10:10]
  plot [-10:10] sin(x)

This one will produce the HTML five page that I described earlier.

  set term canvas standalone mousing size 800,600
  set output "sin.html"
  set xrange [-10:10]
  plot [-10:10] sin(x)

There you go, using the right click, you can zoom and dezoom, and use the small control box to have an even better experience!

Next steps

On OSX, the X11 terminal is not available unless you install XQuartz and probably other softwares. I have seen many posts on Stackoverflow saying that this terminal is even better than canvas, but I have not tried it. That would be the next step to push the tool further.

Do you have any feedback about awesome visualization tools? More gnuplot goodness? Let’s hear about that!


If you have any question/comment, feel free to send me a tweet at @pingtimeout. And if you enjoyed this article and want to support my work, you can always buy me a coffee ☕️.