2017-09-27 97 views

回答

-1

您可以定义y(x)功能,然后绘制它如下:

import matplotlib.pyplot as plt 

def y(x): 
    return [5*i+9 for i in x] 

x = range(0,10) 
plt.plot(x,y(x)) 
plt.show() 

这将产生follwing图:

enter image description here

你可以和用下面的代码得到一张龟的图表,例如:

from turtle import Turtle, Screen 

def y(x): 
    return 5*x+9 

def plotter(turtle, x_range): 
    turtle.penup() 
    for x in x_range: 
     turtle.goto(x, y(x)) 
     turtle.pendown() 

screen = Screen() 
screen.setworldcoordinates(0, 0, 9, 60) 
turtle = Turtle(visible=False) 

x = range(0,10) 
plotter(turtle, x) 

screen.exitonclick() 

主要生产: enter image description here

+0

有关,以及如何使用乌龟,我们如何在乌龟中做到这一点?因为我需要使用setworldcoordinates。 – Reticent

+0

请更新您的问题与您可以接触到的内容(意味着您直到现在写的代码),并更具体地说明您需要什么。 –

+0

请参阅更新的答案。 –

0

这是一个非常普遍的问题的形式方程的曲线图。尝试更具体。这取决于你想如何绘制它。

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(0., 5., 0.2) 
y = 5 * x + 9 
plt.plot(x, y) 
plt.show() 

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(-1., 5., 0.2) 
y = 5 * x + 9 
fig, ax = plt.subplots() 
ax.plot(x,y) 
ax.grid(True, which='both') 
ax.axhline(y=0, color='k') 
ax.axvline(x=0, color='k') 

这些都是很基本的绘图。你可以创建更复杂的图形,但是你必须在你的问题中更具体。

+0

和有关使用龟,以及我们如何能做到这一点的乌龟怎么样?因为我需要使用setworldcoordinates。 – Reticent

+0

我想@Cedric Zoppolo写了一个足够好的答案。如果你错过了什么让我知道/ – sheldonzy

+0

谢谢@sheldonzy – Reticent