Skip to content

DOC: remove constrained_layout kwarg from examples #25198

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

Merged
merged 1 commit into from
Feb 13, 2023

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Feb 11, 2023

PR Summary

The form constrained_layout=True is discouraged in the relevant docstrings since v3.5 (#19892), but is still used across the examples. This PR updates the examples with the preferred form. For the strings, I tried to choose single vs double quotes to be consistent with any strings on nearby lines. Also puts instances of the phrase "constrained layout" in italics, consistent with the decision for the constrained layout tutorial at #25144.

The tutorials and user guide also have constrained_layout=True in places, but I think that can be a separate PR.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@rcomer rcomer added Documentation topic: geometry manager LayoutEngine, Constrained layout, Tight layout labels Feb 11, 2023
import matplotlib.lines as ml
from matplotlib.ticker import Formatter

# Load a numpy record array from yahoo csv data with fields date, open, high,
# low, close, volume, adj_close from the mpl-data/sample_data directory. The
# record array stores the date as an np.datetime64 with a day unit ('D') in
# the date column (``r.date``).
r = (cbook.get_sample_data('goog.npz', np_load=True)['price_data']
.view(np.recarray))
r = cbook.get_sample_data('goog.npz', np_load=True)['price_data'].view(np.recarray)
Copy link
Member Author

Choose a reason for hiding this comment

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

I know we said we wouldn't re-flow, but this line was crying out for it!

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

One small nit. Could self merge if you take it or not so long as the doc build and flake8 pass.

r = r[:9] # get the first 9 days

fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(6, 6),
constrained_layout={'hspace': .15})
layout=ConstrainedLayoutEngine(hspace=0.15))
Copy link
Member

@jklymak jklymak Feb 11, 2023

Choose a reason for hiding this comment

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

I don't mind this, but obscure imports are sometimes not nice. Maybe:

Suggested change
layout=ConstrainedLayoutEngine(hspace=0.15))
layout='constrained')
fig.get_layout_engine().set(hspace=0.15)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't feel strongly either way, so done.

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

As I am not updated on the 3.7 status, I am not merging, but looks good!

@jklymak jklymak modified the milestones: v3.8.0, v3.7.1 Feb 11, 2023
@rcomer rcomer force-pushed the examples-constrained-kwarg branch 2 times, most recently from 8b0a2ff to 8278163 Compare February 12, 2023 13:49
@rcomer rcomer force-pushed the examples-constrained-kwarg branch from 8278163 to e0dcac8 Compare February 12, 2023 13:50
@jklymak jklymak merged commit 0b131ee into matplotlib:main Feb 13, 2023
@lumberbot-app
Copy link

lumberbot-app bot commented Feb 13, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 0b131ee233f27c26db41d309d6c75984027cbd66
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #25198: DOC: remove constrained_layout kwarg from examples'
  1. Push to a named branch:
git push YOURFORK v3.7.x:auto-backport-of-pr-25198-on-v3.7.x
  1. Create a PR against branch v3.7.x, I would have named this PR:

"Backport PR #25198 on branch v3.7.x (DOC: remove constrained_layout kwarg from examples)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@rcomer
Copy link
Member Author

rcomer commented Feb 13, 2023

I’ll take a look at the backport after 3.7.0 is out. Thanks for the reviews!

@rcomer rcomer self-assigned this Feb 13, 2023
rcomer pushed a commit to rcomer/matplotlib that referenced this pull request Feb 14, 2023
…rom examples

Manual backport of matplotlib#25198 due to conflicts in
examples/subplots_axes_and_figures/demo_constrained_layout.py
This was because some of the changes here were right below the section
separators which changed in main at matplotlib#25021.
@rcomer rcomer removed their assignment Feb 14, 2023
jklymak added a commit that referenced this pull request Feb 14, 2023
Backport PR #25198 - DOC: remove constrained_layout kwarg from examples
@rcomer rcomer deleted the examples-constrained-kwarg branch March 4, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants