FIX: tight_layout having negative width axes#10915
Merged
Merged
Conversation
anntzer
reviewed
Mar 29, 2018
| # axes widths: | ||
| h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols | ||
| kwargs["wspace"] = hspace / h_axes | ||
| if h_axes < 0.: |
fbe12fa to
6e08b02
Compare
tacaswell
reviewed
Mar 31, 2018
| if v_axes < 0: | ||
| warnings.warn('tight_layout cannot make axes height small enough ' | ||
| 'to accomodate all axes decorations') | ||
| kwargs["hspace"] = 0.01 |
Member
There was a problem hiding this comment.
This and line 200 above fall back to different numbers, which was intended?
Member
|
Is there a way to test that the axis is not flipped? May check that everything in |
Member
|
👍 to behavior change. |
Member
Author
|
@tacaswell for the test given? I’ve looked at the result (as above) and it’s definitely not flipped. It’s hard to see how someone could change the code to make it flip in the test and keep the warning. |
6e08b02 to
4730719
Compare
Member
Author
|
It seems that somehow we have introduced a code-cov test drop... |
QuLogic
reviewed
Apr 1, 2018
| assert len(w) == 1 | ||
|
|
||
|
|
||
| def test_big_decorators_verticaltal(): |
|
|
||
|
|
||
| def test_big_decorators_horizontal(): | ||
| "Test that warning emited when xlabel too big" |
| assert len(w) == 1 | ||
|
|
||
|
|
||
| def test_big_decorators_horizontal(): |
Member
There was a problem hiding this comment.
codecov drop is because this test name is the same.
| assert len(w) == 1 | ||
|
|
||
|
|
||
| def test_big_decorators_vertical(): |
Member
There was a problem hiding this comment.
Probably the same name as before too if you fix the other's typo.
QuLogic
reviewed
Apr 1, 2018
| margin_left = 0.4999 | ||
| margin_right = 0.4999 | ||
| warnings.warn('The left and right margins cannot be made large ' | ||
| 'enough to accomodate all axes decorations. ') |
4730719 to
abf260f
Compare
dstansby
approved these changes
Apr 7, 2018
Member
Author
|
@meeseeksdev backport to v2.2.x |
tacaswell
added a commit
that referenced
this pull request
Jul 8, 2018
…n-v2.2.x Backport PR #10915 on branch v2.2.x
bergercookie
added a commit
to bergercookie/rqt_plot
that referenced
this pull request
Apr 3, 2020
Matplotlib emits errors like the following under specific canvas
layouts:
```console
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_plot/data_plot/mat_data_plot.py", line 107, in resizeEvent
self.figure.tight_layout()
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1756, in tight_layout
self.subplots_adjust(**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1612, in subplots_adjust
self.subplotpars.update(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 230, in update
raise ValueError('bottom cannot be >= top')
ValueError: bottom cannot be >= top
```
Current patch catches and suppresses that exception.
References:
- matplotlib/matplotlib#10915
- ros-visualization#35
bergercookie
added a commit
to bergercookie/rqt_plot
that referenced
this pull request
Apr 3, 2020
Matplotlib emits errors like the following under specific canvas
layouts:
```console
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_plot/data_plot/mat_data_plot.py", line 107, in resizeEvent
self.figure.tight_layout()
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1756, in tight_layout
self.subplots_adjust(**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1612, in subplots_adjust
self.subplotpars.update(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 230, in update
raise ValueError('bottom cannot be >= top')
ValueError: bottom cannot be >= top
```
Current patch catches and suppresses that exception.
References:
- matplotlib/matplotlib#10915
- ros-visualization#35
dirk-thomas
added a commit
to ros-visualization/rqt_plot
that referenced
this pull request
Apr 3, 2020
* Fix #35 - "bottom cannot be >= top" matplotlib error Matplotlib emits errors like the following under specific canvas layouts: ```console Traceback (most recent call last): File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_plot/data_plot/mat_data_plot.py", line 107, in resizeEvent self.figure.tight_layout() File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1756, in tight_layout self.subplots_adjust(**kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1612, in subplots_adjust self.subplotpars.update(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 230, in update raise ValueError('bottom cannot be >= top') ValueError: bottom cannot be >= top ``` Current patch catches and suppresses that exception. References: - matplotlib/matplotlib#10915 - #35 * renamed to `safe_tight_layout`, inverted logic to avoid duplicating the call Co-authored-by: Dirk Thomas <[email protected]>
dirk-thomas
added a commit
to ros-visualization/rqt_plot
that referenced
this pull request
Apr 3, 2020
* Fix #35 - "bottom cannot be >= top" matplotlib error Matplotlib emits errors like the following under specific canvas layouts: ```console Traceback (most recent call last): File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_plot/data_plot/mat_data_plot.py", line 107, in resizeEvent self.figure.tight_layout() File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1756, in tight_layout self.subplots_adjust(**kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1612, in subplots_adjust self.subplotpars.update(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 230, in update raise ValueError('bottom cannot be >= top') ValueError: bottom cannot be >= top ``` Current patch catches and suppresses that exception. References: - matplotlib/matplotlib#10915 - #35 * renamed to `safe_tight_layout`, inverted logic to avoid duplicating the call Co-authored-by: Dirk Thomas <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Closes #4413 #8062
fig.tight_layout()could cause axes to flip sign if the title was too big, and cause the whole thing to Error if the title was really big. This PR adds a check that the axes width and height is still greater than zero after the margins have been set.It would be nice to just collapse the axes when this happens, but thats actually a bit of work to fake because subplots_adjust 's space parameter is specified as a fraction of average axes width (not the way I'd have expressed this parameter, but...)
Discussion in #4413 suggested that something could be done to ignore the title, but otherwise compute the tight_layout. I think that's theoretically possible, but if someone has a really long title they should probably shorten it or adjust the spacing manually rather than trying to make
tight_layoutdo something magical.For the second and third plots, a warning is emitted...
PR Checklist