You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Automatically Aligned Labels outside Figure with Constrained Layout in Exported File #19152
When using constrained layout on a specific 3-plot layout with automatically aligned labels, the exported plot has labels outside the page. The image in Jupyter Lab renders fine.
Thanks for the bug report. This (coincidentally) appears to have been fixed by #17494 and will be in the 3.4 release, so I don't think there is an action item here, except perhaps to add a test for this? I'll add a "Good first issue" here in case someone wants to add a test. Probably can be done w/o an image comparison, but I'd have to play with it to be sure.
Yes, changing to ax2.set_ylim(1.5) solves the issue, but also changes the axis limits, which may not be desired. The layout problem is rather sensitive to the content of the y-axis labels.
When I use an old version of matplotlib, this detects that the top two labels are 1) not aligned with the third (i.e., the three aren't approximately equal) and 2) have gone off the page (have an x0 greater than 1). When running pytest on my branch of the current repository, everything seems to be fine — the test passes, and the saved PDF looks fine.
I have two beginner's questions:
On https://matplotlib.org/3.2.1/devel/testing.html it says "Some tests have internal side effects that need to be cleaned up after their execution (such as created figures or modified rc params). The pytest fixture mpl_test_settings() will automatically clean these up; there is no need to do anything further." When I run this test using pytest, at least singly instead of as part of the test suite, I am left with that PDF. Is there a particular path to which the PDF should be saved so it will be cleaned up afterward, or something else I need to do to make sure it doesn't hang around?
You pointed me (with some uncertainty) to test_figure.py. However, I see there's also a test_constrainedlayout.py — would it be more appropriate to put my test in the latter document? (I do see a few tests in test_figure.py that include constrained layout)
fig.canvas.draw() seems to do just fine, thank you and oops! I've moved the test to the correct file and hope to submit a pull request within the hour.
Activity
jklymak commentedon Dec 19, 2020
Thanks for the bug report. This (coincidentally) appears to have been fixed by #17494 and will be in the 3.4 release, so I don't think there is an action item here, except perhaps to add a test for this? I'll add a "Good first issue" here in case someone wants to add a test. Probably can be done w/o an image comparison, but I'd have to play with it to be sure.
Firionus commentedon Dec 28, 2020
Yes, changing to
ax2.set_ylim(1.5)solves the issue, but also changes the axis limits, which may not be desired. The layout problem is rather sensitive to the content of the y-axis labels.Hathaway2010 commentedon Jan 19, 2021
I'm brand new to open source — if I were looking to write a test, what files should I look at? Thank you!
jklymak commentedon Jan 19, 2021
@Hathaway2010 Please have a look at https://matplotlib.org/devel/index.html and https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/tests I think maybe
test_figure.pyis where thealign_ylabeltests are? Thanks!Hathaway2010 commentedon Jan 19, 2021
Thank you! I'll see if I can do something in the next few days!
Hathaway2010 commentedon Jan 26, 2021
Hi! I'm pretty sure I've found a test that does the trick: after saving the pdf in the code for reproduction, I do
When I use an old version of matplotlib, this detects that the top two labels are 1) not aligned with the third (i.e., the three aren't approximately equal) and 2) have gone off the page (have an x0 greater than 1). When running pytest on my branch of the current repository, everything seems to be fine — the test passes, and the saved PDF looks fine.
I have two beginner's questions:
Many thanks, and sorry for my ignorance.
Firionus commentedon Jan 26, 2021
Hey,
thanks for taking this on!
I think your code example has lost some linebreaks. If you want line breaks in code, use a Fenced Code Block with three backticks or tildes.
Example:
renders as
Hathaway2010 commentedon Jan 26, 2021
fixed, thank you!
jklymak commentedon Jan 26, 2021
Does this need to be saved as pdf? Or do you just need to trigger a draw via
fig.canvas.draw()Yes, it seems
test_constrained_layout.pyis a good place to put this.Hathaway2010 commentedon Jan 26, 2021
fig.canvas.draw()seems to do just fine, thank you and oops! I've moved the test to the correct file and hope to submit a pull request within the hour.jklymak commentedon Feb 4, 2021
Closed by #19373