Skip to content

DOC: Fix some small issues #26657

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 4 commits into from
Aug 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ def set_figure(self, figure):
self.text.set_figure(figure)
super().set_figure(figure)

def set_axes(self, axes):
self.text.set_axes(axes)
super().set_axes(axes)
# Override the axes property setter to set Axes on our children as well.
@lines.Line2D.axes.setter
def axes(self, new_axes):
self.text.axes = new_axes
lines.Line2D.axes.fset(self, new_axes) # Call the superclass property setter.

def set_transform(self, transform):
# 2 pixel offset
Expand Down
2 changes: 1 addition & 1 deletion galleries/examples/userdemo/connectionstyle_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def demo_con_style(ax, connectionstyle):

for ax in axs.flat:
ax.set(xlim=(0, 1), ylim=(0, 1.25), xticks=[], yticks=[], aspect=1.25)
fig.set_constrained_layout_pads(wspace=0, hspace=0, w_pad=0, h_pad=0)
fig.get_layout_engine().set(wspace=0, hspace=0, w_pad=0, h_pad=0)

plt.show()

Expand Down
15 changes: 6 additions & 9 deletions galleries/users_explain/artists/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
could use this code:
"""

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.patches as patches
Expand Down Expand Up @@ -191,11 +193,6 @@
# edgecolor='yellow', alpha=0.5)
# ax.add_patch(patch)

import numpy as np

import matplotlib.patches as patches
import matplotlib.path as path

fig, ax = plt.subplots()
# Fixing random state for reproducibility
np.random.seed(19680801)
Expand All @@ -213,9 +210,9 @@

nverts = nrects*(1+3+1)
verts = np.zeros((nverts, 2))
codes = np.ones(nverts, int) * path.Path.LINETO
codes[0::5] = path.Path.MOVETO
codes[4::5] = path.Path.CLOSEPOLY
codes = np.full(nverts, Path.LINETO, dtype=int)
codes[0::5] = Path.MOVETO
codes[4::5] = Path.CLOSEPOLY
verts[0::5, 0] = left
verts[0::5, 1] = bottom
verts[1::5, 0] = left
Expand All @@ -225,7 +222,7 @@
verts[3::5, 0] = right
verts[3::5, 1] = bottom

barpath = path.Path(verts, codes)
barpath = Path(verts, codes)
patch = patches.PathPatch(barpath, facecolor='green',
edgecolor='yellow', alpha=0.5)
ax.add_patch(patch)
Expand Down
16 changes: 8 additions & 8 deletions galleries/users_explain/axes/arranging_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def annotate_axes(ax, text, fontsize=18):
fig, axd = plt.subplot_mosaic([['upper left', 'upper right'],
['lower left', 'lower right']],
figsize=(5.5, 3.5), layout="constrained")
for k in axd:
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
for k, ax in axd.items():
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
fig.suptitle('plt.subplot_mosaic()')

# %%
Expand Down Expand Up @@ -200,8 +200,8 @@ def annotate_axes(ax, text, fontsize=18):
fig, axd = plt.subplot_mosaic([['upper left', 'right'],
['lower left', 'right']],
figsize=(5.5, 3.5), layout="constrained")
for k in axd:
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
for k, ax in axd.items():
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
fig.suptitle('plt.subplot_mosaic()')

# %%
Expand All @@ -223,8 +223,8 @@ def annotate_axes(ax, text, fontsize=18):
['lower left', 'right']],
gridspec_kw=gs_kw, figsize=(5.5, 3.5),
layout="constrained")
for k in axd:
annotate_axes(axd[k], f'axd["{k}"]', fontsize=14)
for k, ax in axd.items():
annotate_axes(ax, f'axd[{k!r}]', fontsize=14)
fig.suptitle('plt.subplot_mosaic()')

# %%
Expand Down Expand Up @@ -262,8 +262,8 @@ def annotate_axes(ax, text, fontsize=18):
['lower left', 'lower right']]

fig, axd = plt.subplot_mosaic(outer, layout="constrained")
for k in axd:
annotate_axes(axd[k], f'axd["{k}"]')
for k, ax in axd.items():
annotate_axes(ax, f'axd[{k!r}]')

# %%
# Low-level and advanced grid methods
Expand Down
17 changes: 7 additions & 10 deletions galleries/users_explain/axes/axes_scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,23 @@
# %%
#

todo = ['asinh', 'symlog', 'log', 'logit', ]
fig, axs = plt.subplot_mosaic([['asinh', 'symlog'],
['log', 'logit']], layout='constrained')

x = np.arange(0, 1000)

for td in todo:
ax = axs[td]
if td in ['asinh', 'symlog']:
for name, ax in axs.items():
if name in ['asinh', 'symlog']:
yy = x - np.mean(x)
elif td in ['logit']:
elif name in ['logit']:
yy = (x-np.min(x))
yy = yy / np.max(np.abs(yy))
else:
yy = x

ax.plot(yy, yy)
ax.set_yscale(td)
ax.set_title(td)
ax.set_yscale(name)
ax.set_title(name)

# %%
# Optional arguments for scales
Expand All @@ -131,9 +129,8 @@
fig, axs = plt.subplot_mosaic([['log', 'symlog']], layout='constrained',
figsize=(6.4, 3))

for td in axs:
ax = axs[td]
if td in ['log']:
for name, ax in axs.items():
if name in ['log']:
ax.plot(x, x)
ax.set_yscale('log', base=2)
ax.set_title('log base=2')
Expand Down
4 changes: 2 additions & 2 deletions galleries/users_explain/figure/figure_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ More complex grids can be achieved with `.pyplot.subplot_mosaic` (which wraps

fig, axs = plt.subplot_mosaic([['A', 'right'], ['B', 'right']],
figsize=(4, 3), layout='constrained')
for ax_name in axs:
axs[ax_name].text(0.5, 0.5, ax_name, ha='center', va='center')
for ax_name, ax in axs.items():
ax.text(0.5, 0.5, ax_name, ha='center', va='center')

Sometimes we want to have a nested layout in a Figure, with two or more sets of
Axes that do not share the same subplot grid.
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2466,17 +2466,17 @@ def __init__(self,
to avoid overlapping axes decorations. Can handle complex plot
layouts and colorbars, and is thus recommended.

See :ref:`constrainedlayout_guide`
for examples.
See :ref:`constrainedlayout_guide` for examples.

- 'compressed': uses the same algorithm as 'constrained', but
removes extra space between fixed-aspect-ratio Axes. Best for
simple grids of axes.

- 'tight': Use the tight layout mechanism. This is a relatively
simple algorithm that adjusts the subplot parameters so that
decorations do not overlap. See `.set_tight_layout` for
further details.
decorations do not overlap.

See :ref:`tight_layout_guide` for examples.

- 'none': Do not use a layout engine.

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ def _set_artist_props(self, a):
"""
a.set_figure(self.figure)
if self.isaxes:
# a.set_axes(self.axes)
a.axes = self.axes

a.set_transform(self.get_transform())
Expand Down