Start New Discussion within our Software Development Community

I am new to python . I need source code to draw scatter plot using Python

my Input_1 is something like below:
120321 172.15 -285.03 -870.09
120323 244.31 -257.18 -870.19
120324 274.65 -277.03 -870.10
120327 226.51 -263.98 -870.09
120328 268.55 -271.05 -870.10

my Input_2 is something like below:

120321 ST
120323 SL
120324 ST
120327 ST
120328 OP

My problem is it has to read File Input_1 x,y,z data and plot the points in space such that
if it is "ST" i should get point in Green Color, "SL" means RED color, "OP" means black color

I am attching sample image for this

Can any body help in the code for the above problem

Attachments untitled.JPG 68.07 KB

Here is a code which should read your file and produce a python list of points. Check that it works.

colors = {
    "ST": "green",
    "SL": "red",
    "OP": "black",

point_colors = {}

class Point(object):
    "class for point objects"
    def __init__(self, id, x, y, z): = id
        self.x = x
        self.y = y
        self.z = z
    def color(self):
        return colors[point_colors[]]
    def __repr__(self):
        return "Point(%d, %f, %f, %f)" % (, self.x, self.y, self.z)

def read_files():
    "reads the files and return a list of points"
    the_points = []
    for line in open("Input_1"):
            L = line.strip().split()
            if len(L) != 4:
            id, x, y, z = int(L[0]), float(L[1]), float(L[2]), float(L[3])
            point = Point(id, x, y, z)
    for line in open("Input_2"):
            L = line.strip().split()
            if len(L) != 2:
            id, col = int(L[0]), L[1]
            point_colors[id] = L[1]
    return the_points

the_points = read_files()

if __name__ == "__main__":
    for point in the_points:
        print repr(point)

From this, you must choose a graphic library to plot the points. I suppose that you want to plot the points only in 2D ? See if you can install matplotlib, which has simple commands and nice output.

This article has been dead for over six months. Start a new discussion instead.