跃然 发表于 2021-11-29 10:13:12

【Python】求助!用turtle库画数学函数图像

要画两个函数图像(用海龟库):
1、y=a的x次方
2、y=x的平方

坐标轴可以要可以不要。

哪位大佬能提供一下思路?有代码更好!

suchocolate 发表于 2021-11-29 11:53:33

import turtle
import numpy as np

# y = a ^ x
screen = turtle.Screen()
screen.setworldcoordinates(-11, -1, 11, 4)
a = 1.1#
x1 = np.linspace(-10, 10, 50)
y1 =

turtle.penup()
turtle.setpos(x1, y1)
turtle.pendown()
for i in range(1, len(x1)):
    turtle.goto(x1, y1)
screen.mainloop()



import turtle
import numpy as np


screen = turtle.Screen()

# y = x ^ 2
screen.setworldcoordinates(-11, -1, 11, 125)
x2 = np.linspace(-10, 10, 100)
y2 =

turtle.penup()
turtle.setpos(x2, y2)
turtle.pendown()
for i in range(1, len(x2)):
    turtle.goto(x2, y2)
screen.mainloop()
页: [1]
查看完整版本: 【Python】求助!用turtle库画数学函数图像