File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ def format_legend (ax , ncols = 2 , handles_labels = None , ** kwargs ):
2+ if handles_labels is None :
3+ handles , labels = ax .get_legend_handles_labels ()
4+ else :
5+ handles , labels = handles_labels
6+ nentries = len (handles )
7+
8+ kw = dict (framealpha = 1 , ** kwargs )
9+ split = nentries // ncols * ncols
10+ leg1 = ax .legend (handles = handles [:split ],
11+ labels = labels [:split ],
12+ ncol = ncols ,
13+ loc = "upper right" ,
14+ ** kw )
15+ if nentries % 2 == 0 :
16+ return leg1
17+
18+ ax .add_artist (leg1 )
19+ leg2 = ax .legend (handles = handles [split :],
20+ labels = labels [split :],
21+ ncol = nentries - nentries // ncols * ncols ,
22+ ** kw )
23+
24+ leg2 .remove ()
25+
26+ leg1 ._legend_box ._children .append (leg2 ._legend_handle_box )
27+ leg1 ._legend_box .stale = True
28+ return leg1
You can’t perform that action at this time.
0 commit comments