19

I have an application that prints data to stdout, a floating point number roughly every second. I would like to visualize the numbers as a graph.

What is the easiest way to do this? I'm preferably looking for something I can do in the command line, and ideally without doing any programming or scripting.

7 Answers 7

20

I like termeter with plenty of default options and features.

termeter can visualize data in the terminal. Data can be passed by pipe or file.

 seq 100 | awk 'BEGIN{OFS="\t"; print "x","sin(x)","cos(x)"}{x=$1/10; print x,sin(x),cos(x)}' | termeter

enter image description here

3
  • Looks like termeter is not present in brew.
    – user674669
    Commented Aug 22, 2023 at 6:52
  • Can it plot streaming data?
    – user674669
    Commented Aug 22, 2023 at 9:13
  • On mac os, you can install termeter: $ go install github.com/atsaki/termeter/cmd/termeter@latest
    – user674669
    Commented Aug 22, 2023 at 9:13
7

You can use gnuplot:

gnuplot -e 'set terminal png; plot "input.txt" with lines' > graph.png

You can even pipe input to it, just change the file name to -:

tail input.txt | gnuplot -e 'set terminal png; plot "-" with lines' > graph.png
3
  • 4
    And what if I don't want to save it as a PNG, but show it "live" as it changes? Is that possible? Commented Oct 13, 2014 at 14:57
  • @MadsSkjern: Don't set the terminal and use -p to persist the graphical window.
    – choroba
    Commented Mar 12, 2021 at 19:16
  • 1
    You can use --terminal "dumb 80,40" to print out an ASCII graph.
    – Flimm
    Commented Sep 15, 2021 at 18:48
3

Since your data is getting written to the stdout. You can redirect it to a script using pipe. The script, in turn, would plot the data. To give you a simple example: Here is a short tutorial I wrote to do exactly this: link.

This example shows how to plot 1D data just as you have (time series of floating point numbers).

your_script | python plot_script.py -t 1000

1000 being the history to keep

Hope it helps.

1
  • Nice Answer ! Our community improves from the contributions of those like you. PLEASE keep it up by reviewing other questions that could benefit from your knowledge! Commented Dec 18, 2017 at 13:20
3

Install pip install pipeplot

Use ping ya.ru | grep --line-buffered time | sed -u -e 's#.*time=\([^ ]*\).*#\1#' | pipeplot --min 0

See: gif

2

I have never used it but there is Spark. Sounds like what you want.

1
  • Wow, that is really interesting, and impressive :) However, I need a GUI or smth larger so that I can read the plot in greater detail. Commented Oct 13, 2014 at 15:05
1

Check the package plotext, which allows to plot data directly on terminal using python3.  It is very intuitive, as its use is very similar to the matplotlib package.

sudo -H pip install plotext

As for matplotlib, the main functions are scatter (for single points), plot (for points joined by lines) and show (to actually print the plot on terminal). It is easy to specify the plot dimensions, the point and line styles and whatever to show the axes, number ticks and final equations, which are used to convert the plotted coordinates to the original real values.

Here is an example plot:

     

Here is the code to produce the plot shown above:

import plotext.plot as plx
import numpy as np

l=3000
x=np.arange(0, l)
y=np.sin(4*np.pi/l*np.array(x))*np.exp(-0.5*np.pi/l*x)

plx.scatter(x, y, rows = 17, cols = 70)
plx.show(clear = 0)

The option clear=True inside show is used to clear the terminal before plotting; this is useful, for example, when plotting a continuous flow of data.

The package description provides more information how to customize the plot. The package has been tested on Ubuntu 16 where it works perfectly. Possible future developments (upon request) could involve extension to python2 and to other graphical interfaces (e.g., jupiter). Please let me know if you have any issues using it.

0

If you want something more similar to the watch command then you can use https://github.com/aantn/smag.

Usage would be something like this: smag 'cat file_with_latest_datapoint'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .