8000 tight_layout flips images when making plots without displaying them · Issue #12134 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
tight_layout flips images when making plots without displaying them #12134
Closed
@galenlynch

Description

@galenlynch

Bug report

I am trying to make a bunch of figures on a cluster. In the process of doing so, I have discovered that images are flipped upside down when using tight_layout on GridSpec objects that do not contain the image.

However, this bug only happens when interactive mode is off. Even more strangely, it is not inverted if the figure has already been saved prior to calling tight_layout.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

x, y = np.ogrid[0:6, 0:7]
imdata = x + y

# Two column figure (with simple gridspecs for this example)
gs_left = GridSpec(1, 1, left = 0.05, right = 0.48)
gs_right = GridSpec(1, 1, left = 0.55, right = 0.98)

f = plt.figure()

# Add the image to the right column
im_ax = f.add_subplot(gs_right[0])
im_ax.imshow(imdata, extent = (0, 10, 0, 10), origin = 'upper', aspect = 'auto')

# Uncommenting the following line makes both figures correct
#f.savefig("image_ok")

# Call tight layout on the OTHER grid spec
gs_left.tight_layout(f, rect = [0.05, 0.05, 0.45, 0.95])

f.savefig("image_inverted")

Actual outcome

The image is inverted. The dark portion of the image should be on the bottom left.

image_inverted

Expected outcome

image_ok

Matplotlib version

  • Operating system: Fedora 28
  • Matplotlib version: 2.2.3
  • Matplotlib backend: GTK3Cairo, I think maybe agg with non-interactive?
  • Python version: 3.6.6

Matplotlib was installed from Fedora's package manager.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0