matplotlib: alignment of legend title

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"
    

    enter image description here

  • Right aligned

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

    enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)