-
-
Notifications
You must be signed in to change notification settings - Fork 8k
BUG Ignore invisible axes in computing tight_layout #8244
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ def test_tight_layout7(): | |
ax.set_title('Right Title', loc='right', fontsize=fontsize) | ||
plt.tight_layout() | ||
|
||
|
||
@image_comparison(baseline_images=['tight_layout8']) | ||
def test_tight_layout8(): | ||
'Test automatic use of tight_layout' | ||
|
@@ -157,6 +158,15 @@ def test_tight_layout8(): | |
example_plot(ax, fontsize=24) | ||
|
||
|
||
@image_comparison(baseline_images=['tight_layout9']) | ||
def test_tight_layout9(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are now two test functions in one file with the same name. So the first one gets clobbered by the second one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, please ignore. I misread |
||
# Test tight_layout for non-visible suplots | ||
# GH 8244 | ||
f, axarr = plt.subplots(2, 2) | ||
axarr[1][1].set_visible(False) | ||
plt.tight_layout() | ||
|
||
|
||
# The following test is misleading when the text is removed. | ||
@image_comparison(baseline_images=['outward_ticks'], remove_text=False) | ||
def test_outward_ticks(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,10 @@ def auto_adjust_subplotpars(fig, renderer, | |
for subplots, ax_bbox, (num1, num2) in zip(subplot_list, | ||
ax_bbox_list, | ||
num1num2_list): | ||
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots if ax.get_visible()]) | ||
if all([not ax.get_visible() for ax in subplots]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this just be filtering out invisible axes? Would it make more sense to make sure what ever calls method does that filtering? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I don't understand why you changed what I originally suggested. I suggested putting a filter in the list comprehension down below. Now, it does make sense to skip this iteration if all the axes in this group are invisible. So, I would put the filter in the list comprehension down below, and also change this one from a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grrr, I fail reading comprehension... you do have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first commit tried that approach (see here). But it actually failed to fix the issue. If you try to use that code with the original minimal failing example: import matplotlib.pyplot as plt
f, axarr = plt.subplots(2, 2)
axarr[1][1].set_visible(False)
plt.tight_layout() The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before making a PR, please check that your commit actually fixes the issue...ahem. 😅 Skipping the laying calculations altogether (the approach here) meanwhile seems to work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's why you need both approaches. if a subset of the subplots are not visible, then the way the code is currently, the invisible axes still have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I understand you now—I've re-added the conditional check. |
||
continue | ||
|
||
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots]) | ||
tight_bbox = TransformedBbox(tight_bbox_raw, | ||
fig.transFigure.inverted()) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this passing? The baseline images have not been added...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bear with me here, I have no idea how
matplotlib
handles its tests. 😅 Was planning on getting back to this in a later commit, but you've caught me red-handed.