Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6cce6a5

Browse files
committed
DOC: update docs
1 parent 1851a6c commit 6cce6a5

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
:orphan:
22

3-
Figure legends now have *outside* keyword argument
4-
--------------------------------------------------
5-
If a legend is made on a figure (or subfigure), and constrained_layout is being used,
6-
then setting the *outside* kwarg to *True* on `.Figure.legend` will move axes to
7-
make room for the legend. See :doc:`/tutorials/intermediate/legend_guide` for an
8-
example.
3+
Figure legends can be placed outside figures using constrained_layout
4+
---------------------------------------------------------------------
5+
Constrained layout will make space for Figure legends if they are specified
6+
by a *loc* keyword argument that starts with the string "outside". The
7+
codes are unique from axes codes, in that "outside upper right" will
8+
make room at the top of the figure for the legend, whereas
9+
"outside right upper" will make room on the right-hand side of the figure.
10+
See :doc:`/tutorials/intermediate/legend_guide` for details.

examples/text_labels_and_annotations/figlegend_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
##############################################################################
3333
# Sometimes we do not want the legend to overlap the axes. If you use
34-
# constrained_layout you can specify ``outside=True``, the legend will
35-
# not overlap.
34+
# constrained_layout you can specify "outside right upper", and
35+
# constrained_layout will make room for the legend.
3636

37-
fig, axs = plt.subplots(1, 2, constrained_layout=True)
37+
fig, axs = plt.subplots(1, 2, layout='constrained')
3838

3939
x = np.arange(0.0, 2.0, 0.02)
4040
y1 = np.sin(2 * np.pi * x)
@@ -47,7 +47,7 @@
4747
l3, = axs[1].plot(x, y3, color='tab:green')
4848
l4, = axs[1].plot(x, y4, color='tab:red', marker='^')
4949

50-
fig.legend((l1, l2), ('Line 1', 'Line 2'), 'upper left')
51-
fig.legend((l3, l4), ('Line 3', 'Line 4'), 'upper right', outside=True)
50+
fig.legend((l1, l2), ('Line 1', 'Line 2'), loc='upper left')
51+
fig.legend((l3, l4), ('Line 3', 'Line 4'), loc='outside right upper')
5252

5353
plt.show()

lib/matplotlib/figure.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,6 @@ def legend(self, *args, **kwargs):
11291129
loc = locs[0] + ' ' + locs[1]
11301130

11311131
kwargs['loc'] = loc
1132-
11331132
# explicitly set the bbox transform if the user hasn't.
11341133
l = mlegend.Legend(self, handles, labels, *extra_args,
11351134
bbox_transform=transform, **kwargs)

0 commit comments

Comments
 (0)