3

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))
hiro protagonist
  • 44,693
  • 14
  • 86
  • 111

1 Answers1

3

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))
ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
  • hmm. that looks simple enough! should have been able to come up with that myself! tnanks a lot! – hiro protagonist May 03 '17 at 11:29
  • 1
    Note that according to the docs color.transparency is only available in PDF output (and with some ghostscript devices) http://pyx.sourceforge.net/manual/color.html#color.transparency – JeremyDouglass May 06 '18 at 20:50