Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))
like image 207
hiro protagonist Avatar asked Oct 14 '25 10:10

hiro protagonist


1 Answers

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))
like image 157
ClumsyPuffin Avatar answered Oct 17 '25 00:10

ClumsyPuffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!