pyx模块:如何使颜色透明

pyx module: how to make color transparent

我尝试(但失败了!)让 pyx 在矩形上绘制一个透明圆。

手册中有一个关于 transparency 的条目,但我不知道如何使用它。 matplotlib 会为此使用 alpha - 但我在 pyx 文档中找不到这样的条目。

在我的示例中,我尝试在实心矩形上绘制一个蓝色 - 透明 - 圆环。这里有人知道怎么做吗?

from pyx import canvas, path, color
from pathlib import Path

HERE = Path(__file__).parent

out_path = HERE / 'pyx_test'

c = canvas.canvas()
c.fill(path.rect(-5, -5, 10, 10), [color.rgb.red])
# color.transparency(value) ...?
c.fill(path.circle(0, 0, 6), [color.rgb.blue])
c.writePDFfile(str(out_path))
print('wrote "{}"'.format(out_path))

颜色透明度应与填充方法一起传递。

你可以试试这个:

from pyx import canvas, path, color
from pathlib import Path

HERE = Path(__file__).parent

out_path = HERE / 'pyx_test'

c = canvas.canvas()
c.fill(path.rect(-5, -5, 10, 10), [color.rgb.red])
c.fill(path.circle(0, 0, 6), [color.rgb.blue,color.transparency(0.75)])
c.writePDFfile(str(out_path))
print('wrote "{}"'.format(out_path))