2017-05-03 71 views
2

我試過(並失敗!),以得到pyx在矩形上畫一個透明的圓。pyx模塊:如何使顏色透明

手冊中有關於transparency的條目,但我無法弄清楚如何使用它。 matplotlib會使用alpha - 但我在pyx文檔中找不到這樣的條目。

在我的例子中,我嘗試在一個實心的矩形上繪製一個藍色透明的Cicle。這裏有人知道該怎麼做嗎?

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)) 

回答

2

顏色透明度應與填充方法一起傳遞。

你可以試試這個:

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)) 
+0

哼。看起來很簡單!應該能夠自己想出這個!砸了很多! –