tight_layout does not work with set_visible(False) #8225

Closed
ResidentMario opened this Issue Mar 7, 2017 · 4 comments

Comments

Projects
None yet
3 participants
Contributor

ResidentMario commented Mar 7, 2017

Bug report

Bug summary

  • tight_layout() cooperates with axis('off') but not with set_visible(False).
  • cf. pandas#9351

Code for reproduction

This code fails:

import matplotlib.pyplot as plt
f, axarr = plt.subplots(2, 2)
axarr[1][1].set_visible(False)
plt.tight_layout()

This code succeeds:

import matplotlib.pyplot as plt
f, axarr = plt.subplots(2, 2)
axarr[1][1].axis('off')
plt.tight_layout()

Actual outcome

AttributeError: 'NoneType' object has no attribute 'is_bbox'

Expected outcome

selection_015

Member

WeatherGod commented Mar 8, 2017

Looks like the tight_layout code is iterating over all of the subplots rather than just the visible ones

Member

WeatherGod commented Mar 8, 2017

My suspicion is that adding a condition to the list comprehension:

tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots])

at line 126 of matplotlib.tight_layout.py should do the trick.

tacaswell added this to the 2.0.1 (next bug fix release) milestone Mar 8, 2017

Owner

tacaswell commented Mar 10, 2017

Those two commands do very different things, axis('off') makes the spines invisible, but everything else is still visible ex

fig, ax = plt.subplots()
ax.plot(range(5))
ax.axis('off')

gives
figure_1

where are ax.set_visible(False) makes the Axes object (and all of it's children) are not included in the draw tree.

Contributor

ResidentMario commented Mar 10, 2017

Which is why they look the same output-wise when the plot is empty in the first place (except for dimensional differences), gotcha.

ResidentMario changed the title from tight_layout works with axis('off') but not with set_visible(False) to tight_layout does not work with set_visible(False) Mar 10, 2017

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