Skip to content

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

Merged
pelson merged 1 commit into
matplotlib:v1.2.xfrom
mdboom:image/composite_background
Apr 12, 2013
Merged

Exporting figure as pdf using savefig() messes up axis background in OS X#1894
pelson merged 1 commit into
matplotlib:v1.2.xfrom
mdboom:image/composite_background

Conversation

@mdboom

@mdboom mdboom commented Apr 10, 2013

Copy link
Copy Markdown
Member

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

mdboom commented Apr 10, 2013

Copy link
Copy Markdown
Member

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

mdboom commented Apr 10, 2013

Copy link
Copy Markdown
Member

Can you confirm that the attached patch resolves your issue?

@fgb

fgb commented Apr 11, 2013

Copy link
Copy Markdown
Contributor Author

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

Comment thread src/_image.cpp Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

pelson commented Apr 11, 2013

Copy link
Copy Markdown
Member

👍 LGTM.

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

fgb commented Apr 11, 2013

Copy link
Copy Markdown
Contributor Author

👍 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

fgb commented Apr 11, 2013

Copy link
Copy Markdown
Contributor Author

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

@pelson

pelson commented Apr 12, 2013

Copy link
Copy Markdown
Member

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

mdboom commented Apr 12, 2013

Copy link
Copy Markdown
Member

@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

pelson commented Apr 12, 2013

Copy link
Copy Markdown
Member

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

Nice work @mdboom.

@fgb

fgb commented Apr 12, 2013

Copy link
Copy Markdown
Contributor Author

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

pelson commented Apr 12, 2013

Copy link
Copy Markdown
Member

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

fgb commented Apr 12, 2013

Copy link
Copy Markdown
Contributor Author

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.

3 participants