在横向网格中放置图形(python挑战)

2024-04-29 16:38:50 发布

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

我想在matplotlib中放置子图,这样我就不知道有多少个图(图的可变数量)。你知道吗

栅格尺寸为R*C,因此R<;=C,栅格从左到右,从上到下填充。你知道吗

挑战在于,我想创建一个函数,返回图表编号n的位置(r,c)的元组

所需函数的示例图如下所示,其中group表示n(r,c),即n应输出元组(r,c)的数字

sample
 0(0, 0)   1(0, 1)   4(0, 2)   9(0, 3)  16(0, 4)
 2(1, 0)   3(1, 1)   5(1, 2)  10(1, 3)  17(1, 4)
 6(2, 0)   7(2, 1)   8(2, 2)  11(2, 3)  18(2, 4)
12(3, 0)  13(3, 1)  14(3, 2)  15(3, 3)  19(3, 4)
20(4, 0)  21(4, 1)  22(4, 2)  23(4, 3)  24(4, 4)

Tags: sample函数lt示例数量matplotlib尺寸图表
1条回答
网友
1楼 · 发布于 2024-04-29 16:38:50
x = 0
y = 0
print (x,y)
for i in range(1,5):
    y = i
    print [(x,y) for x in range(i)]
    x = i  
    print [(x,y) for y in range(i+1)]

要添加数字:

tuples=[]

x = 0
y = 0
n = 0
tuples.append((n,(x,y)))
for i in range(1,5):
    y = i
    for x in range(i):
        n+=1
        tuples.append((n,(x,y)))
    x = i  
    for y in range(i+1):
        n+=1
        tuples.append((n,(x,y)))

print tuples

相关问题 更多 >