renderer = figure.canvas.get_renderer()
shift = max([t.get_window_extent(renderer).width for t in legend.get_texts()])
for t in legend.get_texts():
    t.set_ha('right')
t.set_position((shift, 0))
Text alignment in a Matplotlib legend