Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alpha is not set correctly when using eps format #1740

Closed
ppurka opened this issue Feb 8, 2013 · 5 comments
Closed

alpha is not set correctly when using eps format #1740

ppurka opened this issue Feb 8, 2013 · 5 comments

Comments

@ppurka
Copy link

ppurka commented Feb 8, 2013

Consider the following piece of code:

from matplotlib.figure import Figure
figure=Figure()
subplot = figure.add_subplot(111)
import matplotlib.patches as patches
p = patches.Polygon([(0,0), (1,2), (0,1), (-1,2)], fill=True, alpha=0.1)
patches.Patch.get_facecolor(p)
Out[6]: (0.0, 0.0, 1.0, 0.1)

subplot.add_patch(p)
from matplotlib.backends.backend_agg import FigureCanvasAgg
figure.set_canvas(FigureCanvasAgg(figure))
figure.savefig('a.eps')
figure.savefig('a.pdf')

The image a.eps gets a solid fill that would be obtained if we gave alpha=1 (but alpha=0.0 gives an empty fill, as it should). And the image a.pdf gets the correct alpha 0.1 fill.

@mdboom
Copy link
Member

mdboom commented Feb 8, 2013

Unfortunately, the postscript format does not support alpha, so there's little we can do there. Some libraries, such as Cairo, fake it by rendering some things as images, but matplotlib doesn't do that.

@ppurka
Copy link
Author

ppurka commented Feb 8, 2013

According to wikipedia postscript does support transparency. Also, I created this using inkscape and it does render alpha channels: http://ompldr.org/vaGViZg/drawing.eps (However, I think inkscape uses cairo and poppler, which is why it is able to use transparency).

Take away from this is - matplotlib (and ps in general) does not support writing alpha channels. I guess, you can close this ticket, unless you want to keep it open for some far-off future implementation.

@mdboom
Copy link
Member

mdboom commented Feb 8, 2013

The important note in the Wikipedia article is (emphasis mine): The PostScript language has limited support for full (not partial) transparency.

Inkscape does indeed emulate alpha blending by converting parts of the output to an image. The downside of this is that the Postscript file is no longer infinitely scalable, and will start to look blocky when zoomed in. It's a tradeoff, and I understand why it was made. If that behavior is ok for you, you can always use matplotlib's Cairo backend to generate the postscript file.

I'm going to close this bug, but feel free to reopen if any implementation ideas or solutions occur in the future.

@mdboom mdboom closed this as completed Feb 8, 2013
ischwabacher added a commit to ischwabacher/matplotlib that referenced this issue Dec 8, 2015
xref matplotlib#1740

I suspect that the performance implications of this change are acceptable, since it's doing only a tiny fraction of the work the rest of the backend is doing, but I haven't tested it on a large image.

This change will save people like me from considerable embarrassment; I almost submitted a paper with a figure containing an awful lot of black ink where faint shadows should have been, but luckily I have sharp-eyed coauthors.
@darkdragon-001
Copy link

In 764227f, the following warning was added

"The PostScript backend does not support transparency; "

How can I explicitly remove transparency from my figure and avoid this warning?

@tacaswell
Copy link
Member

@darkdragon-001 To answer that we would probably have to see your code. This question is probably best handled on the mailing list.

My complete knee-jerk guess is that you have a legend in your figure which now defaults to a semi-transparent background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants