how to change the position of legend in matplotlib code example Example: position of legend matplotlib plt.legend(loc='upper right')