@@ -162,9 +162,12 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
162162
163163        loc='upper right', bbox_to_anchor=(0.5, 0.5) 
164164
165- ncol  : int, default: 1
165+ ncols  : int, default: 1
166166    The number of columns that the legend has. 
167167
168+     For backward compatibility, the spelling *ncol* is also supported 
169+     but it is discouraged. If both are given, *ncols* takes precedence. 
170+ 
168171prop : None or `matplotlib.font_manager.FontProperties` or dict 
169172    The font properties of the legend. If None (default), the current 
170173    :data:`matplotlib.rcParams` will be used. 
@@ -317,7 +320,7 @@ def __init__(
317320        borderaxespad = None ,  # pad between the axes and legend border 
318321        columnspacing = None ,  # spacing between columns 
319322
320-         ncol = 1 ,     # number of columns 
323+         ncols = 1 ,     # number of columns 
321324        mode = None ,  # horizontal distribution of columns: None or "expand" 
322325
323326        fancybox = None ,  # True: fancy box, False: rounded box, None: rcParam 
@@ -333,6 +336,8 @@ def __init__(
333336        frameon = None ,         # draw frame 
334337        handler_map = None ,
335338        title_fontproperties = None ,  # properties for the legend title 
339+         * ,
340+         ncol = 1   # synonym for ncols (backward compatibility) 
336341    ):
337342        """ 
338343        Parameters 
@@ -418,8 +423,8 @@ def val_or_rc(val, rc_name):
418423
419424        handles  =  list (handles )
420425        if  len (handles ) <  2 :
421-             ncol  =  1 
422-         self ._ncol   =  ncol 
426+             ncols  =  1 
427+         self ._ncols   =   ncols   if   ncols   !=   1   else  ncol 
423428
424429        if  self .numpoints  <=  0 :
425430            raise  ValueError ("numpoints must be > 0; it was %d"  %  numpoints )
@@ -581,6 +586,10 @@ def _set_loc(self, loc):
581586        self .stale  =  True 
582587        self ._legend_box .set_offset (self ._findoffset )
583588
589+     def  set_ncols (self , ncols ):
590+         """Set the number of columns.""" 
591+         self ._ncols  =  ncols 
592+ 
584593    def  _get_loc (self ):
585594        return  self ._loc_real 
586595
@@ -767,12 +776,12 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
767776                handles_and_labels .append ((handlebox , textbox ))
768777
769778        columnbox  =  []
770-         # array_split splits n handles_and_labels into ncol  columns, with the 
771-         # first n%ncol  columns having an extra entry.  filter(len, ...) handles  
772-         # the case where n < ncol : the last ncol -n columns are empty and get  
773-         # filtered out. 
774-         for  handles_and_labels_column  \ 
775-                 in   filter ( len , np .array_split (handles_and_labels , self ._ncol )):
779+         # array_split splits n handles_and_labels into ncols  columns, with the 
780+         # first n%ncols  columns having an extra entry.  filter(len, ...) 
781+         # handles  the case where n < ncols : the last ncols -n columns are empty 
782+         # and get  filtered out. 
783+         for  handles_and_labels_column  in   filter ( 
784+                 len , np .array_split (handles_and_labels , self ._ncols )):
776785            # pack handlebox and labelbox into itembox 
777786            itemboxes  =  [HPacker (pad = 0 ,
778787                                 sep = self .handletextpad  *  fontsize ,
0 commit comments