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