What does a 4-element tuple argument for 'bbox_to_anchor' mean in matplotlib?

后端 未结 2 1477
半阙折子戏
半阙折子戏 2020-11-27 13:39

In the \"Legend location\" section of the \"Legend guide\" in the matplotlib website, there\'s a small script where line 9 is plt.legend(bbox_to_anchor=(0., 1.02, 1.,

2条回答
  •  自闭症患者
    2020-11-27 14:20

    You're right, the 4-tuple in plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3) is set as (x0, y0, width, height) where (x0,y0) are the lower left corner coordinates of the bounding box.

    While those parameters set the bounding box for the legend, the legend's actual vertical size is shrunk to the size that is needed to put the elements in. Further its position is determined only in conjunction with the loc parameter. The loc parameter sets the alignment of the legend inside the bounding box, such that for some cases, no difference will by seen when changing the height, compare e.g. plot (2) and (4).

提交回复
热议问题