从2dpython-ch获取数据

2024-09-28 22:24:33 发布

您现在位置:Python中文网/ 问答频道 /正文

题目可能有点不好,对此我深表歉意。 这是我的二维图表: enter image description here

我想要得到的是定义的“Year”(x axis)和定义的“number of pieces”(y axis)值,以获得红点所属的区域(在本例中为“C”)。 基本上,我想以某种方式将这个图复制到python中,然后读取点所属的特定区域(对于给定的“年”和“件数”数据)。你知道吗

在不安装其他python绘图模块的情况下,这样做是可能的吗? 绘图是一个image.gif文件。你知道吗

编辑:我不想将这个.gif绘图导入python,然后从中读取特定像素(所以不,不是图像处理)。我只想以某种方式在python中重新创建它,即使这意味着要生成一个包含数十个值的长列表。你知道吗


Tags: of数据区域绘图number定义方式图表
1条回答
网友
1楼 · 发布于 2024-09-28 22:24:33

抱歉,在编码时睡着了。。。 检查下面是否适合你

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

相关问题 更多 >