Pyx 中以下参数的类型是什么?

What is the type of the below argument in Pyx?

official documentation描述了图层可以用来设置渲染元素的遮挡

canvas.layer(name, above=None, below=None)

This method creates or gets a layer with name name.

A layer is a canvas itself and can be used to combine drawing operations for ordering purposes, i.e., what is above and below each other. The layer name name is a dotted string, where dots are used to form a hierarchy of layer groups. When inserting a layer, it is put on top of its layer group except when another layer instance of this group is specified by means of the parameters above or below.

好吧,我尝试了以下方法:

c = canvas.canvas().layer("top")
t = canvas.canvas().layer("bot", below="top")
t = canvas.canvas().layer("bot", below=c)
t = canvas.canvas().layer("bot", below=0)

它们都 return 有一些错误。例如字符串版本:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pyx/canvas.py", line 296, in layer
    group, layer = name.split(".", 1)
ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "EdgeRefining/refine_edges.py", line 174, in <module>
    t = canvas.canvas().layer("bot", below="top")
  File "/usr/lib/python3/dist-packages/pyx/canvas.py", line 312, in layer
    self.items.insert(self.items.index(self.layers[below]), self.layers[name])
KeyError: 'top'

有人用过这个功能吗?

图层是 canvas 个 canvas 实例。这是一个例子:

from pyx import *

c = canvas.canvas()
l1 = c.layer('l1')
l2 = c.layer('l2')

l1.fill(path.circle(0, 0, 2), [color.rgb.red])
l2.fill(path.circle(3, 0, 2), [color.rgb.green])

c.writePDFfile()

现在可以在创建图层l2时添加below='l1',红圈会放在绿圈上面。您的代码中的问题是,您一直在创建新的 canvas 实例,但是,将在同一个 canvas.

中使用多个层