matplotlib: alignment of legend title

后端 未结 2 1335
南方客
南方客 2021-02-02 10:27

In matplotlib, how can I adjust the alignment of the legend title? It is always centered, but I need it to be left aligned with the legend box. I tried to change the al

2条回答
  •  悲&欢浪女
    2021-02-02 10:47

    You may align the complete legend box setting leg._legend_box.align. This aligns everything inside the legend box, but the effect is the desired one to have the title on either side of the box instead of the center.

    • Left aligned

      leg = plt.legend(title="Title")
      leg._legend_box.align = "left"
      

    • Right aligned

      leg = plt.legend(title="Title")
      leg._legend_box.align = "right"
      

提交回复
热议问题