Skip to content

Instantly share code, notes, and snippets.

@xuhdev
Created March 27, 2012 11:40
Show Gist options
  • Save xuhdev/2215209 to your computer and use it in GitHub Desktop.
Save xuhdev/2215209 to your computer and use it in GitHub Desktop.
Use matplotlib to plot scatter point graph for a list of ascii data from standard input
#!/bin/env python
import matplotlib.pyplot as plt
import getopt
import sys
try:
opts, args = getopt.getopt(sys.argv[1:], 'x:y:')
except:
print >>sys.stderr, "Argument error."
sys.exit(1)
# set default xlabel and y label
xlabel = 'x'
ylabel = 'y'
for option, arg in opts:
if option == '-x':
xlabel = arg
elif option == '-y':
ylabel = arg
xes = []
yes = []
for line in sys.stdin:
splited_line = line.split()
x = float(splited_line[0])
y = float(splited_line[1])
xes.append(x)
yes.append(y)
plt.plot(xes, yes, 'ro')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment