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

Skip to content

Commit cd84080

Browse files
committed
Remove support for deprecated legend/table locations.
1 parent ecae132 commit cd84080

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

doc/api/api_changes_3.3/behaviour.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,11 @@ be kept by passing it as a keyword argument to `.Axes.hist`.
192192
`.Legend` and `.OffsetBox` subclasses (`.PaddedBox`, `.AnchoredOffsetbox`, and
193193
`.AnnotationBbox`) no longer directly keep track of the visibility of their
194194
underlying `.Patch` artist, but instead pass that flag down to the `.Patch`.
195+
196+
`.Legend` and `.Table` no longer allow invalid locations
197+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198+
This affects legends produced on an Axes (`.Axes.legend` and `.pyplot.legend`)
199+
and on a Figure (`.Figure.legend` and `.pyplot.figlegend`). Figure legends also
200+
no longer accept the unsupported ``'best'`` location. Previously, invalid Axes
201+
locations would use ``'best'`` and invalid Figure locations would used ``'upper
202+
right'``.

lib/matplotlib/legend.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -444,28 +444,15 @@ def __init__(self, parent, handles, labels,
444444
loc = 'upper right'
445445
if isinstance(loc, str):
446446
if loc not in self.codes:
447-
if self.isaxes:
448-
cbook.warn_deprecated(
449-
"3.1", message="Unrecognized location {!r}. Falling "
450-
"back on 'best'; valid locations are\n\t{}\n"
451-
"This will raise an exception %(removal)s."
452-
.format(loc, '\n\t'.join(self.codes)))
453-
loc = 0
454-
else:
455-
cbook.warn_deprecated(
456-
"3.1", message="Unrecognized location {!r}. Falling "
457-
"back on 'upper right'; valid locations are\n\t{}\n'"
458-
"This will raise an exception %(removal)s."
459-
.format(loc, '\n\t'.join(self.codes)))
460-
loc = 1
447+
raise ValueError(
448+
"Unrecognized location {!r}. Valid locations are\n\t{}\n"
449+
.format(loc, '\n\t'.join(self.codes)))
461450
else:
462451
loc = self.codes[loc]
463452
if not self.isaxes and loc == 0:
464-
cbook.warn_deprecated(
465-
"3.1", message="Automatic legend placement (loc='best') not "
466-
"implemented for figure legend. Falling back on 'upper "
467-
"right'. This will raise an exception %(removal)s.")
468-
loc = 1
453+
raise ValueError(
454+
"Automatic legend placement (loc='best') not implemented for "
455+
"figure legend.")
469456

470457
self._mode = mode
471458
self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)

lib/matplotlib/table.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,9 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
293293

294294
if isinstance(loc, str):
295295
if loc not in self.codes:
296-
cbook.warn_deprecated(
297-
"3.1", message="Unrecognized location {!r}. Falling back "
298-
"on 'bottom'; valid locations are\n\t{}\n"
299-
"This will raise an exception %(removal)s."
296+
raise ValueError(
297+
"Unrecognized location {!r}. Valid locations are\n\t{}"
300298
.format(loc, '\n\t'.join(self.codes)))
301-
loc = 'bottom'
302299
loc = self.codes[loc]
303300
self.set_figure(ax.figure)
304301
self._axes = ax

0 commit comments

Comments
 (0)