Skip to main content

Plotting data in the terminal.

Project description

buildstatus coverage

Irwin

Plotting data in the terminal.

Project homepage: https://github.com/eerimoq/irwin

Installation

$ pip install irwin

Examples

Command line

The plot subcommand

Read all data from given file and plot it. Data points are separated by any whitespace character.

$ echo "0,2 1,1 2,0 3,-1 4,1 5,3 6,5 7,7" > data.txt
$ irwin plot data.txt
https://github.com/eerimoq/irwin/raw/master/docs/plot.gif

Give -t scatter to create a scatter plot.

$ python3 -c "import math, random, numpy ; \
      x = numpy.linspace(0, 3 * math.pi, 200) ; \
      y = [v + random.random() / 4 for v in numpy.cos(x)] ; \
      print(' '.join([f'{x},{y}' for x, y in zip(x, y)]))" > data.txt
$ irwin plot -t scatter data.txt
https://github.com/eerimoq/irwin/raw/master/docs/scatter.gif

Add more samples by running python3 -c "import random ; print(f'{random.random()},{random.random()}') periodically.

$ irwin plot -t scatter \
      -c "python3 -c \"import random ; print(f'{random.random()},{random.random()}')\"" \
      data.txt
https://github.com/eerimoq/irwin/raw/master/docs/scatter-command.gif
The watch subcommand

Run cat /proc/uptime | awk '{ print \$1 }' periodically any plot its output.

$ irwin watch "cat /proc/uptime | awk '{ print \$1 }'"
https://github.com/eerimoq/irwin/raw/master/docs/uptime.gif

This is how to plot the CPU load on a machine with 4 CPUs.

$ irwin watch -a delta -y 0 -Y 100 -s -0.25 -o 100 \
      "head -1 /proc/stat | awk '{ print \$5 }'"
https://github.com/eerimoq/irwin/raw/master/docs/cpu.gif

Scripting

Using a canvas

Draw on the canvas and render it. Print the rendered canvas.

import irwin

canvas = irwin.Canvas(width=40,
                      height=20,
                      x_min=0,
                      x_max=10,
                      y_min=0,
                      y_max=10)

# Draw the canvas edges.
canvas.draw_line(0, 0, 0, 10)
canvas.draw_line(0, 10, 10, 10)
canvas.draw_line(10, 10, 10, 0)
canvas.draw_line(10, 0, 0, 0)

# Draw a cross.
canvas.draw_line(0, 0, 10, 10)
canvas.draw_line(0, 10, 10, 0)

# Draw four points.
canvas.draw_point(5, 2.5)
canvas.draw_point(5, 7.5)
canvas.draw_point(2.5, 5)
canvas.draw_point(7.5, 5)

print(canvas.render())

The output:

⡟⢍⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⡩⢻
⡇⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⢸
⡇⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠑⢄⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⢸
⡇⠀⠀⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⢸
⡇⠀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⢸
⣧⣊⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣑⣼
Line plot

Not yet implemented.

import math
import numpy
import irwin

x = numpy.linspace(0, 2 * math.pi)
y = numpy.sin(x)

print(irwin.plot(x, y))
Scatter plot

Not yet implemented.

import math
import random
import numpy
import irwin

x = numpy.linspace(0, 2 * math.pi)
y = numpy.cos(x) + random.random() / 4;

print(irwin.scatter(x, y))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

irwin-0.11.0.tar.gz (13.4 kB view details)

Uploaded Source

File details

Details for the file irwin-0.11.0.tar.gz.

File metadata

  • Download URL: irwin-0.11.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.8.0

File hashes

Hashes for irwin-0.11.0.tar.gz
Algorithm Hash digest
SHA256 b6e6eaf00529f814751bcf759b804f4679c6a0487f78ec14bc820e952192880a
MD5 757a3a0240a62cccc42cf1ddf92b0bb6
BLAKE2b-256 97b54ad6227db65ff1a0c1122e0cc4e8f8c436f6ccaa6d802427fb083b12252c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page