-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Rename ncol parameter in legend to ncols #23198
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
``ncol`` keyword argument to ``legend`` renamed to ``ncols`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The ``ncol`` keyword argument to `~.Axes.legend` for controlling the number of | ||
columns is renamed to ``ncols`` for consistency with the ``ncols`` and | ||
``nrows`` keywords of `~.Figure.subplots` and `~.GridSpec`. | ||
``ncol`` is still supported though. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,9 +162,12 @@ def _update_bbox_to_anchor(self, loc_in_canvas): | |
|
||
loc='upper right', bbox_to_anchor=(0.5, 0.5) | ||
|
||
ncol : int, default: 1 | ||
ncols : int, default: 1 | ||
The number of columns that the legend has. | ||
|
||
For backward compatibility, the spelling *ncol* is also supported | ||
but it is discouraged. If both are given, *ncols* takes precedence. | ||
|
||
prop : None or `matplotlib.font_manager.FontProperties` or dict | ||
The font properties of the legend. If None (default), the current | ||
:data:`matplotlib.rcParams` will be used. | ||
|
@@ -317,7 +320,7 @@ def __init__( | |
borderaxespad=None, # pad between the axes and legend border | ||
columnspacing=None, # spacing between columns | ||
|
||
ncol=1, # number of columns | ||
ncols=1, # number of columns | ||
mode=None, # horizontal distribution of columns: None or "expand" | ||
|
||
fancybox=None, # True: fancy box, False: rounded box, None: rcParam | ||
|
@@ -333,6 +336,8 @@ def __init__( | |
frameon=None, # draw frame | ||
handler_map=None, | ||
title_fontproperties=None, # properties for the legend title | ||
*, | ||
ncol=1 # synonym for ncols (backward compatibility) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this? I think you have to leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone uses this with a positional argument it will be picked up as As #23166 is in, we are on the way to keyword only arguments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops yes I agree. |
||
): | ||
""" | ||
Parameters | ||
|
@@ -418,8 +423,8 @@ def val_or_rc(val, rc_name): | |
|
||
handles = list(handles) | ||
if len(handles) < 2: | ||
ncol = 1 | ||
self._ncol = ncol | ||
ncols = 1 | ||
self._ncols = ncols if ncols != 1 else ncol | ||
|
||
if self.numpoints <= 0: | ||
raise ValueError("numpoints must be > 0; it was %d" % numpoints) | ||
|
@@ -581,6 +586,10 @@ def _set_loc(self, loc): | |
self.stale = True | ||
self._legend_box.set_offset(self._findoffset) | ||
|
||
def set_ncols(self, ncols): | ||
"""Set the number of columns.""" | ||
self._ncols = ncols | ||
oscargus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _get_loc(self): | ||
return self._loc_real | ||
|
||
|
@@ -767,12 +776,12 @@ def _init_legend_box(self, handles, labels, markerfirst=True): | |
handles_and_labels.append((handlebox, textbox)) | ||
|
||
columnbox = [] | ||
# array_split splits n handles_and_labels into ncol columns, with the | ||
# first n%ncol columns having an extra entry. filter(len, ...) handles | ||
# the case where n < ncol: the last ncol-n columns are empty and get | ||
# filtered out. | ||
for handles_and_labels_column \ | ||
in filter(len, np.array_split(handles_and_labels, self._ncol)): | ||
# array_split splits n handles_and_labels into ncols columns, with the | ||
# first n%ncols columns having an extra entry. filter(len, ...) | ||
# handles the case where n < ncols: the last ncols-n columns are empty | ||
# and get filtered out. | ||
for handles_and_labels_column in filter( | ||
len, np.array_split(handles_and_labels, self._ncols)): | ||
# pack handlebox and labelbox into itembox | ||
itemboxes = [HPacker(pad=0, | ||
sep=self.handletextpad * fontsize, | ||
|
Uh oh!
There was an error while loading. Please reload this page.