pythonpython-2.7python-3.xpyx

pyx module: how to make color transparent


i tried (and failed!) to get pyx to draw a transparent circle over a rectangle.

there is an entry about transparency in the manual but i was unable to figure out how to use it. matplotlib would use alpha for that - but i could find no such entry in the pyx documentation.

in my example i try to draw a blue - transparent - cicle over a solid rectangle. does anybody here know how to do that?

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

Solution

  • Color transparency should 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))