Skip to content

Instantly share code, notes, and snippets.

@pjvandehaar
Created January 8, 2016 01:45
Show Gist options
  • Save pjvandehaar/8f5307aacb2dda5f8914 to your computer and use it in GitHub Desktop.
Save pjvandehaar/8f5307aacb2dda5f8914 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess, random
rows, columns = (int(r) for r in subprocess.check_output([b'stty', b'size']).split())
data1 = [(x*0.1, random.gauss(40,3) - 30*(x/100.)**2) for x in range(0,100)]
data2 = [(x*0.1, random.gauss(20,3) + 30*(x/100.)**2) for x in range(0,100)]
gnuplot = subprocess.Popen("/usr/bin/gnuplot", stdin=subprocess.PIPE)
gnuplot.stdin.write("set term dumb {} {}\n".format(columns - 3, rows - 3).encode())
gnuplot.stdin.write(b"set rmargin 0\n")
gnuplot.stdin.write(b"set tmargin 0\n")
gnuplot.stdin.write(b"plot '-' title 'foo', '-' title 'bar'\n")
for data in (data1, data2):
for x,y in data:
gnuplot.stdin.write("{} {}\n".format(x,y).encode())
gnuplot.stdin.write(b"e\n")
gnuplot.stdin.write(b"exit\n")
gnuplot.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment