Skip to content

PDF output does not respect zorder when using imshow #2517

Closed

Description

@mrbump

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?

Activity

  1. mdboom commented on Oct 14, 2013

    @mdboom
    Member

    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.

  2. pelson commented on Oct 28, 2013

    @pelson
    Member

    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).

  3. tacaswell commented on Feb 21, 2014

    @tacaswell
    Member

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

  4. added 2 commits that reference this issue on Mar 25, 2014
  5. christianbrodbeck commented on Sep 26, 2014

    @christianbrodbeck
    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
  6. tacaswell commented on Sep 27, 2014

    @tacaswell
    Member

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

  7. modified the milestones: , v1.3.x, v1.4.x on Sep 27, 2014
  8. modified the milestones: v1.4.x, on Feb 7, 2015
  9. tacaswell commented on Jul 17, 2015

    @tacaswell
    Member

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

  10. tacaswell commented on Jul 17, 2015

    @tacaswell
    Member

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

  11. modified the milestones: , on Jul 17, 2015
  12. tacaswell commented on Jul 17, 2015

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions