Skip to content

DOC: remove constrained_layout kwarg from tutorials and user guide #25249

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 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/users/faq/howto_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ supplied.
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1, 2, constrained_layout=True, figsize=(6, 2))
fig, ax = plt.subplots(1, 2, layout='constrained', figsize=(6, 2))

ax[0].set_title('Ticks seem out of order / misplaced')
x = ['5', '20', '1', '9'] # strings
Expand Down
4 changes: 2 additions & 2 deletions tutorials/colors/colormap-manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def plot_examples(colormaps):
data = np.random.randn(30, 30)
n = len(colormaps)
fig, axs = plt.subplots(1, n, figsize=(n * 2 + 2, 3),
constrained_layout=True, squeeze=False)
layout='constrained', squeeze=False)
for [ax, cmap] in zip(axs.flat, colormaps):
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
fig.colorbar(psm, ax=ax)
Expand Down Expand Up @@ -197,7 +197,7 @@ def plot_examples(colormaps):
def plot_linearmap(cdict):
newcmp = LinearSegmentedColormap('testCmap', segmentdata=cdict, N=256)
rgba = newcmp(np.linspace(0, 1, 256))
fig, ax = plt.subplots(figsize=(4, 3), constrained_layout=True)
fig, ax = plt.subplots(figsize=(4, 3), layout='constrained')
col = ['r', 'g', 'b']
for xx in [0.25, 0.5, 0.75]:
ax.axvline(xx, color='0.7', linestyle='--')
Expand Down
4 changes: 2 additions & 2 deletions tutorials/colors/colormapnorms.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
Z1 = (1 + np.sin(Y * 10.)) * X**2

fig, ax = plt.subplots(2, 1, constrained_layout=True)
fig, ax = plt.subplots(2, 1, layout='constrained')

pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=0.5),
cmap='PuBu_r', shading='auto')
Expand Down Expand Up @@ -207,7 +207,7 @@
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = ((Z1 - Z2) * 2)[:-1, :-1]

fig, ax = plt.subplots(2, 2, figsize=(8, 6), constrained_layout=True)
fig, ax = plt.subplots(2, 2, figsize=(8, 6), layout='constrained')
ax = ax.flatten()

# Default norm:
Expand Down
4 changes: 2 additions & 2 deletions tutorials/intermediate/arranging_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def annotate_axes(ax, text, fontsize=18):
#
# When a *GridSpec* is explicitly used, you can adjust the layout
# parameters of subplots that are created from the *GridSpec*. Note this
# option is not compatible with ``constrained_layout`` or
# option is not compatible with *constrained layout* or
# `.Figure.tight_layout` which both ignore *left* and *right* and adjust
# subplot sizes to fill the figure. Usually such manual placement
# requires iterations to make the Axes tick labels not overlap the Axes.
Expand Down Expand Up @@ -389,7 +389,7 @@ def annotate_axes(ax, text, fontsize=18):
def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)):
return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d)

fig = plt.figure(figsize=(8, 8), constrained_layout=False)
fig = plt.figure(figsize=(8, 8), layout='constrained')
outer_grid = fig.add_gridspec(4, 4, wspace=0, hspace=0)

for a in range(4):
Expand Down
28 changes: 14 additions & 14 deletions tutorials/intermediate/constrainedlayout_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):

# %%
# If you specify a list of Axes (or other iterable container) to the
# ``ax`` argument of ``colorbar``, constrained_layout will take space from
# ``ax`` argument of ``colorbar``, *constrained layout* will take space from
# the specified Axes.

fig, axs = plt.subplots(2, 2, figsize=(4, 4), layout="constrained")
Expand Down Expand Up @@ -162,8 +162,8 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# =======
#
# Legends can be placed outside of their parent axis.
# Constrained-layout is designed to handle this for :meth:`.Axes.legend`.
# However, constrained-layout does *not* handle legends being created via
# *Constrained layout* is designed to handle this for :meth:`.Axes.legend`.
# However, *constrained layout* does *not* handle legends being created via
# :meth:`.Figure.legend` (yet).

fig, ax = plt.subplots(layout="constrained")
Expand All @@ -186,7 +186,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# with ``fig.savefig('outname.png', bbox_inches='tight')``. Note,
# however, that the legend's ``get_in_layout`` status will have to be
# toggled again to make the saved file work, and we must manually
# trigger a draw if we want constrained_layout to adjust the size
# trigger a draw if we want *constrained layout* to adjust the size
# of the Axes before printing.

fig, axs = plt.subplots(1, 2, figsize=(4, 2), layout="constrained")
Expand All @@ -195,7 +195,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
axs[1].plot(np.arange(10), label='This is a plot')
leg = axs[1].legend(loc='center left', bbox_to_anchor=(0.8, 0.5))
leg.set_in_layout(False)
# trigger a draw so that constrained_layout is executed once
# trigger a draw so that constrained layout is executed once
# before we turn it off when printing....
fig.canvas.draw()
# we want the legend included in the bbox_inches='tight' calcs.
Expand Down Expand Up @@ -288,7 +288,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
for ax in axs.flat:
example_plot(ax, hide_labels=True)
# this has no effect because the space set in the gridspec trumps the
# space set in constrained_layout.
# space set in *constrained layout*.
fig.get_layout_engine().set(w_pad=4 / 72, h_pad=4 / 72, hspace=0.0,
wspace=0.0)

Expand Down Expand Up @@ -319,7 +319,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# that can be set, either in a script or in the :file:`matplotlibrc`
# file. They all have the prefix ``figure.constrained_layout``:
#
# - *use*: Whether to use constrained_layout. Default is False
# - *use*: Whether to use *constrained layout*. Default is False
# - *w_pad*, *h_pad*: Padding around Axes objects.
# Float representing inches. Default is 3./72. inches (3 pts)
# - *wspace*, *hspace*: Space between subplot groups.
Expand All @@ -335,7 +335,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# Use with GridSpec
# =================
#
# constrained_layout is meant to be used
# *Constrained layout* is meant to be used
# with :func:`~matplotlib.figure.Figure.subplots`,
# :func:`~matplotlib.figure.Figure.subplot_mosaic`, or
# :func:`~matplotlib.gridspec.GridSpec` with
Expand Down Expand Up @@ -454,7 +454,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# ================================
#
# There can be good reasons to manually set an Axes position. A manual call
# to `~.axes.Axes.set_position` will set the Axes so constrained_layout has
# to `~.axes.Axes.set_position` will set the Axes so *constrained layout* has
# no effect on it anymore. (Note that *constrained layout* still leaves the
# space for the Axes that is moved).

Expand Down Expand Up @@ -497,12 +497,12 @@ def example_plot(ax, fontsize=12, hide_labels=False):
#
# *Constrained layout* usually adjusts the Axes positions on each draw
# of the figure. If you want to get the spacing provided by
# *Constrained layout* but not have it update, then do the initial
# *constrained layout* but not have it update, then do the initial
# draw and then call ``fig.set_layout_engine('none')``.
# This is potentially useful for animations where the tick labels may
# change length.
#
# Note that *Constrained layout* is turned off for ``ZOOM`` and ``PAN``
# Note that *constrained layout* is turned off for ``ZOOM`` and ``PAN``
# GUI events for the backends that use the toolbar. This prevents the
# Axes from changing position during zooming and panning.
#
Expand All @@ -517,7 +517,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# number of rows and columns is the same for each call.
# The reason is that each call to `.pyplot.subplot` will create a new
# `.GridSpec` instance if the geometry is not the same, and
# *Constrained layout*. So the following works fine:
# *constrained layout*. So the following works fine:

fig = plt.figure(layout="constrained")

Expand Down Expand Up @@ -588,7 +588,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# Debugging
# =========
#
# Constrained-layout can fail in somewhat unexpected ways. Because it uses
# *Constrained layout* can fail in somewhat unexpected ways. Because it uses
# a constraint solver the solver can find solutions that are mathematically
# correct, but that aren't at all what the user wants. The usual failure
# mode is for all sizes to collapse to their smallest allowable value. If
Expand All @@ -615,7 +615,7 @@ def example_plot(ax, fontsize=12, hide_labels=False):
# into rows and columns, with the relative width of the Axes in those
# rows and columns set by *width_ratios* and *height_ratios*.
#
# In constrained_layout, each gridspec gets a *layoutgrid* associated with
# In *constrained layout*, each gridspec gets a *layoutgrid* associated with
# it. The *layoutgrid* has a series of ``left`` and ``right`` variables
# for each column, and ``bottom`` and ``top`` variables for each row, and
# further it has a margin for each of left, right, bottom and top. In each
Expand Down
2 changes: 1 addition & 1 deletion tutorials/intermediate/legend_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
# --------------
#
# Sometimes it makes more sense to place a legend relative to the (sub)figure
# rather than individual Axes. By using ``constrained_layout`` and
# rather than individual Axes. By using *constrained layout* and
# specifying "outside" at the beginning of the *loc* keyword argument,
# the legend is drawn outside the Axes on the (sub)figure.

Expand Down