marco
marco

Reputation: 893

Getting the data from 2d python chart

The topic title might be a bit bad, I apologize for that. Here is a 2d chart I have: enter image description here

What I would like to get is for defined "Year" (x axis) and defined "number of pieces" (y axis) values, to get the area to which the red point would belong (in this case "C"). Basically I would like to somehow replicate this plot to python, and then read the specific areas to which points belong (for give "Year" and "number of pieces" data).

Is something like this possible without installing some additional python plot modules? The plot is an image .gif file.

EDIT: I do not want to import this .gif plot to python and then read particular pixel from it (so no, not image processing). I would just like to somehow recreate it in python, even if that would mean generating a long list of tens of values.

Upvotes: 0

Views: 319

Answers (1)

mlwn
mlwn

Reputation: 1187

Sorry, Fell asleep while coding... Check below if it works for you

graph = [
            [1998.4, 1998.5, 1998.7, 1999.2, 1999.8, 2001.1],
            [1999.8, 2000.0, 2000.5, 2000.9, 2001.6, 2003.0],
            [2001.1, 2001.3, 2001.7, 2002.1, 2002.8, 2004.1],
            [2002.3, 2002.7, 2003.1, 2003.5, 2004.0, 2004.9],
            [2003.8, 2003.8, 2004.0, 2004.2, 2004.5, 2005.0]
        ]
MyStop = False

def interPolate(x0, y0, x1, y1, x):
        if x1 == x0:
                return y0
        else:
                return y0 + (y1-y0)*(x-x0)/(x1-x0)

while not MyStop:
        nop = raw_input("Input the number of pieces [0 to 5,000] (x to stop): ")
        if nop <> "x":
                if nop.isdigit():
                        inop = int(nop)
                        if inop <= 5000 and inop >= 0:
                                y = raw_input("Input the year: ")
                                if y.isdigit():
                                        yy = int(y)
                                        val = []
                                        for aList in graph:
                                                for j in range(len(aList)-1):
                                                        if 1000*j <= inop and 1000*(j+1) > inop:
                                                                val.append(interPolate(1000*j, aList[j], 1000*(j+1),aList[j+1],inop))
                                        if yy > val[4]:
                                                print "Value in Region : F."
                                        elif yy > val[3]:
                                                print "Value in Region : E."
                                        elif yy > val[2]:
                                                print "Value in Region : D."
                                        elif yy > val[1]:
                                                print "Value in Region : C."
                                        elif yy > val[0]:
                                                print "Value in Region : B."
                                        else:
                                                print "Value in Region : A."
                                else:
                                        print "Something Went Wrong !! :("
        else:
                print "Will Exit Now! ByeBye."
                MyStop = True

Upvotes: 1

Related Questions