Created
March 27, 2012 11:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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