Pyx module: how to make a color transparent
I tried (and failed!) To get pyx
to draw a transparent circle over the rectangle.
there is an entry about in the manual transparency
, but I was unable to figure out how to use it. matplotlib
will use alpha
for this, but I couldn't find such an entry in the documentation pyx
.
in my example i am trying to draw a blue transparent shape over a solid rectangle. does anyone here know how to do this?
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))
+3
source to share
1 answer
The transparency of the color must be passed along with the fill method.
you can try this:
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))
+3
source to share