Skip to content

Instantly share code, notes, and snippets.

@xuhdev
Created March 17, 2012 08:48
Show Gist options
  • Save xuhdev/2056798 to your computer and use it in GitHub Desktop.
Save xuhdev/2056798 to your computer and use it in GitHub Desktop.
Use matplotlib to plot scatter graph for ascii data
#!/bin/env python
# plot scatter graph for ascii data
#
# The file is read from stdin.
#
# data format:
#
# x0 y0
# x1 y1
# ..
# xn yn
#
# example file:
#
# -3 9
# -2 4
# -1 1
# 0 0
# 1 1
# 2 4
# 3 9
#
import matplotlib.pyplot as plt
import sys
xes = []
yes = []
for line in sys.stdin.readlines():
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.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment