Skip to content

PDF output does not respect zorder when using imshow #2517

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

Closed
mrbump opened this issue Oct 14, 2013 · 8 comments
Closed

PDF output does not respect zorder when using imshow #2517

mrbump opened this issue Oct 14, 2013 · 8 comments

Comments

@mrbump
Copy link

mrbump commented Oct 14, 2013

I already posted this as a question on Stack Overflow.

Minimal example:

import numpy as np
import matplotlib.pyplot as plt

img = np.arange(100).reshape((10,10))
plt.imshow(img, extent = [0.25, 0.75, 0.25, 0.75], zorder = 10)
plt.imshow(img, extent = [0.1, 0.9, 0.1, 0.9], zorder = 1)
plt.plot([0, 1], [0, 1], color = 'black', zorder = 5)
plt.axis([0, 1, 0, 1])

plt.savefig('img.png')

When exporting to PNG, the output is as expected:
img

However, when saving to PDF, the zorder is not respected (the line is plotted over both images):
img pdf

Is this a bug?

@mdboom
Copy link
Member

mdboom commented Oct 14, 2013

I think this comes from the fact that in the vector backends, images are "simplified" into a single image. We should probably discuss whether we want to continue doing that or perhaps make it optional.

@pelson
Copy link
Member

pelson commented Oct 28, 2013

or perhaps make it optional.

I could have sworn it was optional already....

http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure (see suppressComposite). It turns out you can configure the behaviour on the figure, but not on the Axes.

To fix this on PDF output one would need to override the "option_image_nocomposite" method on the renderer (PDF renderer in this case).

@tacaswell
Copy link
Member

@pelson This seems to be an already fixed case, closing. Please re-open if I am confused.

Khodeir added a commit to Khodeir/matplotlib that referenced this issue Mar 25, 2014
Khodeir added a commit to Khodeir/matplotlib that referenced this issue Mar 27, 2014
@christianbrodbeck
Copy link
Contributor

Having the same problem. As normal user, how do I fix this? Inserting this does not work, nor does False:

fig = plt.figure()
fig.suppressComposite = True

@tacaswell
Copy link
Member

Ah, I was confused when I closed closed this before.

@tacaswell tacaswell reopened this Sep 27, 2014
@tacaswell tacaswell modified the milestones: v1.5.x, v1.3.x, v1.4.x Sep 27, 2014
@tacaswell tacaswell modified the milestones: v1.4.x, 1.5.0 Feb 7, 2015
@tacaswell
Copy link
Member

@Khodeir It looks like you were working on this, did that ever turn into a PR?

@tacaswell
Copy link
Member

@stretch97 I could have sworn that we fixed this as part of a different issue...

@tacaswell tacaswell modified the milestones: proposed next point release, next point release Jul 17, 2015
@tacaswell
Copy link
Member

This is fixed by #4061

Adding

matplotlib.rcParams['image.composite_image'] = False

to the script suppresses the compositing of images which lets z-order be respected (but makes your pdf files bigger).

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

No branches or pull requests

5 participants