Friday, September 16, 2016

Make legend outside the box - Python



Put the legend to the right of the axis, outside the axes. Also grab the legend object. bbox_to_anchor determines where relative to the axis object the legend is.

lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

Then when you save, tell savefig that it needs to not freak out about the legend:

fig.savefig(fig_title, bbox_extra_artists=(lgd,), bbox_inches='tight')

No comments:

Post a Comment