Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: tight_layout having negative width axes#10915

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

jklymak
Copy link
Member

@jklymakjklymak commentedMar 29, 2018
edited
Loading

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 maketight_layout do something magical.

importmatplotlib.pyplotaspltfig,axs=plt.subplots(1,2,figsize=(6,2))leng=95axs[0].set_title('A'+('a'*leng))axs[0].set_yticks([])axs[1].set_title('B'+('b'*leng))axs[1].set_yticks([])axs[0].set_xlabel('title length %d'%leng)fig.tight_layout()plt.show()

t45
t46
t95

For the second and third plots, a warning is emitted...

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@jklymakjklymak added this to thev3.0 milestoneMar 29, 2018
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols
kwargs["wspace"] = hspace / h_axes
if h_axes < 0.:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

0 without dot

if v_axes < 0:
warnings.warn('tight_layout cannot make axes height small enough '
'to accomodate all axes decorations')
kwargs["hspace"] = 0.01
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This and line 200 above fall back to different numbers, which was intended?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks! Fixed.

@tacaswell
Copy link
Member

Is there a way to test that the axis is not flipped? May check that everything intransAxes is positive?

@tacaswell
Copy link
Member

👍 to behavior change.

@jklymak
Copy link
MemberAuthor

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

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Test is good enough for me.

@jklymakjklymakforce-pushed thefix-tight-layout-too-small branch from6e08b02 to4730719CompareApril 1, 2018 04:00
@jklymak
Copy link
MemberAuthor

It seems that somehow we have introduced a code-cov test drop...

assert len(w) == 1


def test_big_decorators_verticaltal():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

verticaltal?



def test_big_decorators_horizontal():
"Test that warning emited when xlabel too big"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

emitted (and in other places)

assert len(w) == 1


def test_big_decorators_horizontal():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

codecov drop is because this test name is the same.

jklymak reacted with thumbs up emoji
assert len(w) == 1


def test_big_decorators_vertical():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Probably the same name as before too if you fix the other's typo.

jklymak reacted with thumbs up emoji
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. ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

accommodate (and below)

@jklymakjklymakforce-pushed thefix-tight-layout-too-small branch from4730719 toabf260fCompareApril 1, 2018 15:00
@efiringefiring merged commite2a0813 intomatplotlib:masterApr 7, 2018
@jklymakjklymak deleted the fix-tight-layout-too-small branchApril 9, 2018 17:11
@jklymak
Copy link
MemberAuthor

@meeseeksdev backport to v2.2.x

tacaswell added a commit that referenced this pull requestJul 8, 2018
bergercookie added a commit to bergercookie/rqt_plot that referenced this pull requestApr 3, 2020
Matplotlib emits errors like the following under specific canvaslayouts:```consoleTraceback (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 requestApr 3, 2020
Matplotlib emits errors like the following under specific canvaslayouts:```consoleTraceback (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 requestApr 3, 2020
*Fix#35 - "bottom cannot be >= top" matplotlib errorMatplotlib emits errors like the following under specific canvaslayouts:```consoleTraceback (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 callCo-authored-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
dirk-thomas added a commit to ros-visualization/rqt_plot that referenced this pull requestApr 3, 2020
*Fix#35 - "bottom cannot be >= top" matplotlib errorMatplotlib emits errors like the following under specific canvaslayouts:```consoleTraceback (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 callCo-authored-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@QuLogicQuLogicQuLogic left review comments

@anntzeranntzeranntzer left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.0.0
Development

Successfully merging this pull request may close these issues.

Long axis title alters xaxis length and direction withplt.tight_layout()
7 participants
@jklymak@tacaswell@QuLogic@anntzer@timhoffm@dstansby@efiring

[8]ページ先頭

©2009-2025 Movatter.jp