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

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

Merged
merged 1 commit into from Apr 12, 2013

Conversation

mdboom
Copy link
Member

@mdboom 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

@mdboom
Copy link
Member

mdboom commented Apr 10, 2013

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

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

mdboom commented Apr 10, 2013

Can you confirm that the attached patch resolves your issue?

@fgb
Copy link
Contributor Author

fgb commented Apr 11, 2013

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

@@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 added a commit to mdboom/matplotlib that referenced this pull request Apr 11, 2013
@pelson
Copy link
Member

pelson commented Apr 11, 2013

👍 LGTM.

mdboom added a commit to mdboom/matplotlib that referenced this pull request Apr 11, 2013
@fgb
Copy link
Contributor Author

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
@fgb
Copy link
Contributor Author

fgb commented Apr 11, 2013

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

@pelson
Copy link
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)?

@mdboom
Copy link
Member

mdboom commented Apr 12, 2013

@pelson: Good suggestions. Done.

pelson added a commit that referenced this pull request Apr 12, 2013
Fixes background coloring of multiple images on the same axes.
@pelson pelson merged commit b9d3422 into matplotlib:v1.2.x Apr 12, 2013
@pelson
Copy link
Member

pelson commented Apr 12, 2013

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

Nice work @mdboom.

@fgb
Copy link
Contributor Author

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!

@pelson
Copy link
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 😉

@fgb
Copy link
Contributor Author

fgb commented Apr 12, 2013

Will not! ✌️

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

Successfully merging this pull request may close these issues.

None yet

3 participants