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

Already on GitHub? Sign in to your account

Exporting figure as pdf using savefig() messes up axis background in OS X #1894

Merged
merged 1 commit into from Apr 12, 2013

Conversation

Projects
None yet
3 participants
Contributor

mdboom commented Apr 10, 2013

I'm trying to change the axis background on a plot where several imshow() calls render images in various locations via the extent parameter.

When I save a pdf of the figure using savefig(), I lose the background color if the axis displays more than one image. Note that this doesn't happen when exporting a png of the same figure.

Example code and the corresponding output [stackoverflow.com].

Could this be a bug with the MacOSX backend I'm using?

Note: I'm using matplotlib 1.2.1 installed via pip running on Python 2.7.4

Owner

mdboom commented Apr 10, 2013

Seems to be unrelated to macosx (which isn't used to produce PDFs). Looking into it now.

@mdboom mdboom added a commit to mdboom/matplotlib that referenced this pull request Apr 10, 2013

@mdboom mdboom Fix #1894: Composite images do not have a transparent background faebb37
Owner

mdboom commented Apr 10, 2013

Can you confirm that the attached patch resolves your issue?

Contributor

fgb commented Apr 11, 2013

Thanks for the clarification on the backend. I'll test this tomorrow and let you know.

@pelson pelson and 1 other commented on an outdated diff Apr 11, 2013

src/_image.cpp
@@ -820,7 +820,7 @@
pixfmt pixf(*imo->rbufOut);
renderer_base rb(pixf);
- rb.clear(agg::rgba(1, 1, 1, 1));
+ rb.clear(agg::rgba(1, 1, 1, 0));
@pelson

pelson Apr 11, 2013

Member

This is fine by me, but I wonder why we need to set the RGB to 1? Is there a similar solution here to the one proposed in #1868?

@mdboom

mdboom Apr 11, 2013

Owner

Yeah -- at the end of the day, it doesn't matter, but maybe it does make sense to be consistent with #1868. I'll fix this up.

@mdboom mdboom added a commit to mdboom/matplotlib that referenced this pull request Apr 11, 2013

@mdboom mdboom Fix #1894: Composite images do not have a transparent background 5177dce
Member

pelson commented Apr 11, 2013

👍 LGTM.

@mdboom mdboom added a commit to mdboom/matplotlib that referenced this pull request Apr 11, 2013

@mdboom mdboom Fix #1894: Composite images do not have a transparent background eeb52e7
Contributor

fgb commented Apr 11, 2013

👍 This commit resolves my issue. Thanks for the prompt fix!

Note: I can't believe compilation on OS X is so simple these days. I used to patch make.osx before I could do anything, which generally meant looking for the latest links to the dependencies. I guess brew came to the rescue.

@fgb fgb closed this Apr 11, 2013

@fgb fgb reopened this Apr 11, 2013

Contributor

fgb commented Apr 11, 2013

Apologies, closed by mistake. I'm assuming you'll close this issue when merging the pull request.

Member

pelson commented Apr 12, 2013

Apologies, closed by mistake. I'm assuming you'll close this issue when merging the pull request.

Yep.

@mdboom - I wonder if it is worth having some alpha in the axis background, just to test that it is working. I also wonder whether we should use some colour in the actual images being drawn, perhaps simply arr = np.arange(12).reshape(3, 4)?

Owner

mdboom commented Apr 12, 2013

@pelson: Good suggestions. Done.

@pelson pelson added a commit that referenced this pull request Apr 12, 2013

@pelson pelson Merge pull request #1894 from mdboom/image/composite_background
Fixes background coloring of multiple images on the same axes.
b9d3422

@pelson pelson merged commit b9d3422 into matplotlib:v1.2.x Apr 12, 2013

1 check failed

default The Travis build could not complete due to an error
Details
Member

pelson commented Apr 12, 2013

Thanks for reporting @fgb - this will be fixed in v1.3.

Nice work @mdboom.

Contributor

fgb commented Apr 12, 2013

My pleasure. Now I'll be able to include the relevant figures in PDF in my dissertation instead of relying on PNGs. Thanks @mdboom, @pelson!

Member

pelson commented Apr 12, 2013

Now I'll be able to include the relevant figures in PDF in my dissertation instead of relying on PNGs

Cool. Don't forget to cite us: http://matplotlib.org/citing.html 😉

Contributor

fgb commented Apr 12, 2013

Will not! ✌️

@mdboom mdboom deleted the mdboom:image/composite_background branch Aug 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment