Skip to content
Advertisement

Matplotlib: changing the alpha of plotted image with AnnotationBox artist

This question is into relation with the following answer: https://stackoverflow.com/a/53851017/8814577

I’ve used the in the answer described method to drop images in a boxplot with AnnotionBox (from matplotlib.offsetbox) and it worked out great. However I’ve been searching but did not find an obvious solution to change the alpha channel (transparency) of the plotted image. I’ve been looking into trying to change the alpha of the artist object or trying to add it with bboxprops but to no avail. My sense is that the alpha channel does not apply when plotting an artist object that is an OffsetImage object. Is it maybe possible to change the alpha of an OffsetImage object?

My current solution would be either to overlay the plotted images with white transparent images or by changing the transparency of the plotted images themselves. However I would like to avoid this method as it would create a large amount of images since I’m using the result further in an animation.

Thank you for anyone who wants to look into this.

(full disclosure: I do not have enough rep to comment everywhere and I got rightfully burned misusing by asking my related question as an answer there. However I do think by being forced making a new question this extremely clutters stackoverflow, just a remark to keep in mind.)

Advertisement

Answer

The answer proposed by ImportanceOfBeingErnest works. I feel a bit ridiculous I couldn’t come up with just trying that out or finding it in docs.

Advertisement